Skip to content

Commit

Permalink
Plot largest features only
Browse files Browse the repository at this point in the history
  • Loading branch information
veghp committed Nov 28, 2024
1 parent b5e7d9a commit 8f932eb
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions ediacara/Comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,38 +76,34 @@ class CustomTranslator(dna_features_viewer.BiopythonTranslator):

def compute_filtered_features(self, features):
"""Display only selected features."""
has_dnacauldron_annotation = False
n = 10 # max number of features that fit on the plot
if len(features) <= n:
return features # plot all, no need for calculations

filtered_features = []
for feature in features:
# DNA Cauldron annotations:
# DNA Cauldron annotations have priority:
try:
if "From " in str(feature.qualifiers.get("note", "")):
filtered_features += [feature]
except:
pass

if len(filtered_features) == 0: # no DNA Cauldron annotations
# Keep up to n longest features:
n = 10
if len(features) > n:
feature_lengths = []
for feature in features:
feature_lengths += [len(feature.location)]
feature_lengths.sort(reverse=True)
max_length = feature_lengths[n]
for feature in features:
if len(feature.location) > max_length:
filtered_features += [feature]
else:
filtered_features = features
else:
# add 4-letter overhang annotations:
for feature in features:
try: # may not have a 'label'
if len(feature.qualifiers.get("label", "")[0]) == 4:
filtered_features += [feature]
except:
pass
# Fill remaining spaces:
n_remains = n - len(filtered_features)
feature_lengths = []
for feature in features:
try:
if "From " in str(feature.qualifiers.get("note", "")):
continue # already added above
except:
pass
feature_lengths += [len(feature.location)]
feature_lengths.sort(reverse=True)
max_length = feature_lengths[n_remains]
for feature in features:
if len(feature.location) > max_length:
filtered_features += [feature]

return filtered_features

Expand Down

0 comments on commit 8f932eb

Please sign in to comment.