Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -78,6 +78,7 @@ def add_protein_features(cds_info):
|
|
| 78 |
|
| 79 |
# Updated Function to generate genome diagram
|
| 80 |
def create_genome_diagram(genbank_content, output_file_path, colors_dict, diagram_type="linear", diagram_size=(30, 10)):
|
|
|
|
| 81 |
record = SeqIO.read(StringIO(genbank_content), "genbank")
|
| 82 |
gd_diagram = Diagram(record.id)
|
| 83 |
|
|
@@ -85,18 +86,20 @@ def create_genome_diagram(genbank_content, output_file_path, colors_dict, diagra
|
|
| 85 |
max_tracks = len(colors_dict)
|
| 86 |
track_indices = {feature_type: idx+1 for idx, feature_type in enumerate(colors_dict.keys())}
|
| 87 |
feature_tracks = {}
|
|
|
|
| 88 |
for feature_type, idx in track_indices.items():
|
| 89 |
feature_tracks[feature_type] = gd_diagram.new_track(
|
| 90 |
idx, name=feature_type, scale=False, greytrack=False, height=0.5
|
| 91 |
)
|
| 92 |
-
|
|
|
|
| 93 |
|
| 94 |
for feature in record.features:
|
| 95 |
feature_type = feature.type
|
| 96 |
if feature_type in colors_dict:
|
| 97 |
color = colors.HexColor(colors_dict[feature_type])
|
| 98 |
-
#
|
| 99 |
-
feature_set =
|
| 100 |
feature_set.add_feature(
|
| 101 |
feature,
|
| 102 |
color=color,
|
|
|
|
| 78 |
|
| 79 |
# Updated Function to generate genome diagram
|
| 80 |
def create_genome_diagram(genbank_content, output_file_path, colors_dict, diagram_type="linear", diagram_size=(30, 10)):
|
| 81 |
+
from Bio.Graphics.GenomeDiagram import Diagram, Track, FeatureSet
|
| 82 |
record = SeqIO.read(StringIO(genbank_content), "genbank")
|
| 83 |
gd_diagram = Diagram(record.id)
|
| 84 |
|
|
|
|
| 86 |
max_tracks = len(colors_dict)
|
| 87 |
track_indices = {feature_type: idx+1 for idx, feature_type in enumerate(colors_dict.keys())}
|
| 88 |
feature_tracks = {}
|
| 89 |
+
feature_sets = {} # Dictionary to store FeatureSets
|
| 90 |
for feature_type, idx in track_indices.items():
|
| 91 |
feature_tracks[feature_type] = gd_diagram.new_track(
|
| 92 |
idx, name=feature_type, scale=False, greytrack=False, height=0.5
|
| 93 |
)
|
| 94 |
+
# Store the FeatureSet
|
| 95 |
+
feature_sets[feature_type] = feature_tracks[feature_type].new_set()
|
| 96 |
|
| 97 |
for feature in record.features:
|
| 98 |
feature_type = feature.type
|
| 99 |
if feature_type in colors_dict:
|
| 100 |
color = colors.HexColor(colors_dict[feature_type])
|
| 101 |
+
# Retrieve the FeatureSet from the dictionary
|
| 102 |
+
feature_set = feature_sets[feature_type]
|
| 103 |
feature_set.add_feature(
|
| 104 |
feature,
|
| 105 |
color=color,
|