comparison src/genecluster_sequence/__init__.py @ 25:99435bb90725 draft

Uploaded
author bgruening
date Fri, 18 Oct 2013 03:35:17 -0400
parents
children
comparison
equal deleted inserted replaced
24:b942dfd80819 25:99435bb90725
1 #!/usr/bin/env python
2
3 """
4 antiSMASH 2.0 output plugin to write all cluster proteins to a file (*_genecluster_proteins.fa)
5 """
6 import logging
7 import textwrap
8 from os import path
9 from antismash import utils
10
11 name = "genecluster_proteins"
12 short_description = "Ouptut gene clusters as FASTA sequences"
13 # Output plugins are sorted by priority, lower numbers get run first
14 priority = 9
15
16 def write(seq_records, options):
17 """Write all cluster proteins to a file
18
19 Args:
20 seq_records (iterable): An iterable containing Bio.SeqRecords
21 options (argparse.Namespace): The options passed to the program
22 """
23 basename = seq_records[0].id
24 output_name = path.join(options.outputfoldername, "%s_genecluster_proteins.fa" % basename)
25 logging.debug("Writing seq_records to %r" % output_name)
26
27 with open(output_name, 'w+') as handle:
28 for seq_record in seq_records:
29 clusters = utils.get_cluster_features(seq_record)
30 for cluster in clusters:
31 clustertype = utils.get_cluster_type(cluster)
32 clusternr = utils.get_cluster_number(cluster)
33 for feature in utils.get_cluster_cds_features(cluster, seq_record):
34 qual = feature.qualifiers
35 fasta_header = '>%s:%s %s #%s - %s\n' % (qual['locus_tag'][0], qual['protein_id'][0], clustertype, clusternr, qual['product'][0])
36 handle.write( fasta_header )
37 handle.write( '%s\n' % '\n'.join( textwrap.wrap(qual['translation'][0], 60) ) )