-
Notifications
You must be signed in to change notification settings - Fork 0
/
operon.py
51 lines (39 loc) · 1.9 KB
/
operon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'''
@author: ichaudr
'''
from features import AnnotatedHit, GenomeFeature
class Operon:
def __init__(self, genome_fragment_name, genome_accession, genome_features, strand):
self.features = []
self.genome_fragment_name = genome_fragment_name
self.genome_accession =genome_accession
self.genome_features = genome_features
self.strand = strand
def add_feature(self, feature):
'''
Appends feature to the list of features associated with this operon and sorts it from 5' to 3'
Parameters
----------
feature: GenomeFeature object
Feature to be added
Returns
-------
None
'''
#Checking if the feature is present in the features associated with the genome for this operon.
if feature in self.genome_features:
self.features.append(feature)
self.features = sorted(self.features, key=lambda feature: feature.five_end)
#else:
# raise Exception("The feature you are trying to add is not in the genome assigned for this operon.")
def __str__(self):
try:
to_return = "OPERON:" + str(self.genome_fragment_name) + "(" + str(self.genome_accession) + ")\nStrand: " + str(self.strand) + "\n"
for f in self.features:
if isinstance(f, AnnotatedHit):
to_return = to_return + "\tOriginal Query: " + f.query_accession + "\tHit Accession: " + f.protein_accession + "\tLocus Tag: " + f.locus_tag + "\n"
elif isinstance(f, GenomeFeature):
to_return = to_return + "\tIntergenic Feature: " + f.protein_accession + "\tLocus Tag: " + f.locus_tag + "\n"
except:
to_return = "An error occured printing an operon for " + str(self.genome_fragment_name) + "(" + str(self.genome_accession) + ")\n"
return to_return