comparison src/genecluster_sequence/__init__.py @ 22:225d40beff1a draft

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