Spaces:
Running
Running
Commit
·
2e65f0b
1
Parent(s):
d7b6536
bug fixing
Browse files
app.py
CHANGED
|
@@ -1025,11 +1025,14 @@ class PeptideStructureGenerator:
|
|
| 1025 |
@staticmethod
|
| 1026 |
def mol_to_sdf_bytes(mol):
|
| 1027 |
"""Convert RDKit molecule to SDF file bytes"""
|
| 1028 |
-
|
|
|
|
| 1029 |
writer = Chem.SDWriter(sio)
|
| 1030 |
writer.write(mol)
|
| 1031 |
writer.close()
|
| 1032 |
-
|
|
|
|
|
|
|
| 1033 |
|
| 1034 |
def process_input(smiles_input=None, file_obj=None, show_linear=False,
|
| 1035 |
show_segment_details=False, generate_3d=False, use_uff=False):
|
|
@@ -1109,7 +1112,12 @@ def process_input(smiles_input=None, file_obj=None, show_linear=False,
|
|
| 1109 |
|
| 1110 |
# Check if cyclic using analyzer's method
|
| 1111 |
is_cyclic, peptide_cycles, aromatic_cycles = analyzer.is_cyclic(smiles)
|
| 1112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1113 |
|
| 1114 |
# Create cyclic structure visualization
|
| 1115 |
img_cyclic = annotate_cyclic_structure(mol, sequence)
|
|
@@ -1123,13 +1131,14 @@ def process_input(smiles_input=None, file_obj=None, show_linear=False,
|
|
| 1123 |
buf.seek(0)
|
| 1124 |
img_linear = Image.open(buf)
|
| 1125 |
plt.close(fig_linear)
|
| 1126 |
-
|
| 1127 |
# Add summary to output
|
| 1128 |
summary = "Summary:\n"
|
| 1129 |
-
summary += f"Sequence: {
|
|
|
|
| 1130 |
summary += f"Is Cyclic: {'Yes' if is_cyclic else 'No'}\n"
|
| 1131 |
-
if is_cyclic:
|
| 1132 |
-
summary += f"Peptide Cycles: {', '.join(peptide_cycles)}\n"
|
| 1133 |
#summary += f"Aromatic Cycles: {', '.join(aromatic_cycles)}\n"
|
| 1134 |
|
| 1135 |
return summary + output_text, img_cyclic, img_linear, structure_files
|
|
|
|
| 1025 |
@staticmethod
|
| 1026 |
def mol_to_sdf_bytes(mol):
|
| 1027 |
"""Convert RDKit molecule to SDF file bytes"""
|
| 1028 |
+
# First write to StringIO in text mode
|
| 1029 |
+
sio = StringIO()
|
| 1030 |
writer = Chem.SDWriter(sio)
|
| 1031 |
writer.write(mol)
|
| 1032 |
writer.close()
|
| 1033 |
+
|
| 1034 |
+
# Convert the string to bytes
|
| 1035 |
+
return sio.getvalue().encode('utf-8')
|
| 1036 |
|
| 1037 |
def process_input(smiles_input=None, file_obj=None, show_linear=False,
|
| 1038 |
show_segment_details=False, generate_3d=False, use_uff=False):
|
|
|
|
| 1112 |
|
| 1113 |
# Check if cyclic using analyzer's method
|
| 1114 |
is_cyclic, peptide_cycles, aromatic_cycles = analyzer.is_cyclic(smiles)
|
| 1115 |
+
three_letter = '-'.join(sequence_parts)
|
| 1116 |
+
one_letter = ''.join(analyzer.three_to_one.get(aa.split('(')[0], 'X') for aa in sequence_parts)
|
| 1117 |
+
|
| 1118 |
+
if is_cyclic:
|
| 1119 |
+
three_letter = f"cyclo({three_letter})"
|
| 1120 |
+
one_letter = f"cyclo({one_letter})"
|
| 1121 |
|
| 1122 |
# Create cyclic structure visualization
|
| 1123 |
img_cyclic = annotate_cyclic_structure(mol, sequence)
|
|
|
|
| 1131 |
buf.seek(0)
|
| 1132 |
img_linear = Image.open(buf)
|
| 1133 |
plt.close(fig_linear)
|
| 1134 |
+
|
| 1135 |
# Add summary to output
|
| 1136 |
summary = "Summary:\n"
|
| 1137 |
+
summary += f"Sequence: {three_letter}\n"
|
| 1138 |
+
summary += f"One-letter code: {one_letter}\n"
|
| 1139 |
summary += f"Is Cyclic: {'Yes' if is_cyclic else 'No'}\n"
|
| 1140 |
+
#if is_cyclic:
|
| 1141 |
+
#summary += f"Peptide Cycles: {', '.join(peptide_cycles)}\n"
|
| 1142 |
#summary += f"Aromatic Cycles: {', '.join(aromatic_cycles)}\n"
|
| 1143 |
|
| 1144 |
return summary + output_text, img_cyclic, img_linear, structure_files
|