Spaces:
Running
Running
yinuozhang
commited on
Commit
•
82fb410
1
Parent(s):
260f3d0
minor fix
Browse files
app.py
CHANGED
@@ -551,7 +551,7 @@ def create_enhanced_linear_viz(sequence, smiles):
|
|
551 |
plt.tight_layout()
|
552 |
return fig
|
553 |
|
554 |
-
def process_input(smiles_input=None, file_obj=None, show_linear=False):
|
555 |
"""Process input and create visualizations using PeptideAnalyzer"""
|
556 |
analyzer = PeptideAnalyzer()
|
557 |
|
@@ -574,23 +574,37 @@ def process_input(smiles_input=None, file_obj=None, show_linear=False):
|
|
574 |
|
575 |
# Process segments and build sequence
|
576 |
sequence_parts = []
|
577 |
-
output_text = "
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
output_text +=
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
588 |
else:
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
594 |
|
595 |
# Check if cyclic using analyzer's method
|
596 |
is_cyclic, peptide_cycles, aromatic_cycles = analyzer.is_cyclic(smiles)
|
@@ -610,14 +624,14 @@ def process_input(smiles_input=None, file_obj=None, show_linear=False):
|
|
610 |
plt.close(fig_linear)
|
611 |
|
612 |
# Add summary to output
|
613 |
-
summary =
|
614 |
summary += f"Sequence: {sequence}\n"
|
615 |
summary += f"Is Cyclic: {'Yes' if is_cyclic else 'No'}\n"
|
616 |
if is_cyclic:
|
617 |
summary += f"Peptide Cycles: {', '.join(peptide_cycles)}\n"
|
618 |
summary += f"Aromatic Cycles: {', '.join(aromatic_cycles)}\n"
|
619 |
|
620 |
-
return summary +
|
621 |
|
622 |
except Exception as e:
|
623 |
return f"Error processing SMILES: {str(e)}", None, None
|
@@ -644,19 +658,37 @@ def process_input(smiles_input=None, file_obj=None, show_linear=False):
|
|
644 |
# Process this SMILES
|
645 |
segments = analyzer.split_on_bonds(smiles)
|
646 |
sequence_parts = []
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
654 |
|
655 |
# Get cyclicity and create sequence
|
656 |
is_cyclic, peptide_cycles, aromatic_cycles = analyzer.is_cyclic(smiles)
|
657 |
sequence = f"cyclo({'-'.join(sequence_parts)})" if is_cyclic else '-'.join(sequence_parts)
|
658 |
|
659 |
-
output_text += f"SMILES: {smiles}\n"
|
660 |
output_text += f"Sequence: {sequence}\n"
|
661 |
output_text += f"Is Cyclic: {'Yes' if is_cyclic else 'No'}\n"
|
662 |
if is_cyclic:
|
@@ -673,32 +705,16 @@ def process_input(smiles_input=None, file_obj=None, show_linear=False):
|
|
673 |
|
674 |
iface = gr.Interface(
|
675 |
fn=process_input,
|
676 |
-
|
677 |
-
gr.Textbox(
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
),
|
682 |
-
gr.File(
|
683 |
-
label="Or upload a text file with SMILES",
|
684 |
-
file_types=[".txt"],
|
685 |
-
type="binary"
|
686 |
-
),
|
687 |
-
gr.Checkbox(
|
688 |
-
label="Show linear representation"
|
689 |
-
)
|
690 |
],
|
691 |
outputs=[
|
692 |
-
gr.Textbox(
|
693 |
-
|
694 |
-
|
695 |
-
),
|
696 |
-
gr.Image(
|
697 |
-
label="2D Structure with Annotations"
|
698 |
-
),
|
699 |
-
gr.Image(
|
700 |
-
label="Linear Representation"
|
701 |
-
)
|
702 |
],
|
703 |
title="Peptide Structure Analyzer and Visualizer",
|
704 |
description="""
|
|
|
551 |
plt.tight_layout()
|
552 |
return fig
|
553 |
|
554 |
+
def process_input(smiles_input=None, file_obj=None, show_linear=False, show_segment_details=False):
|
555 |
"""Process input and create visualizations using PeptideAnalyzer"""
|
556 |
analyzer = PeptideAnalyzer()
|
557 |
|
|
|
574 |
|
575 |
# Process segments and build sequence
|
576 |
sequence_parts = []
|
577 |
+
output_text = ""
|
578 |
+
|
579 |
+
# Only include segment analysis in output if requested
|
580 |
+
if show_segment_details:
|
581 |
+
output_text += "Segment Analysis:\n"
|
582 |
+
for i, segment in enumerate(segments):
|
583 |
+
output_text += f"\nSegment {i}:\n"
|
584 |
+
output_text += f"Content: {segment['content']}\n"
|
585 |
+
output_text += f"Bond before: {segment.get('bond_before', 'None')}\n"
|
586 |
+
output_text += f"Bond after: {segment.get('bond_after', 'None')}\n"
|
587 |
+
|
588 |
+
residue, mods = analyzer.identify_residue(segment)
|
589 |
+
if residue:
|
590 |
+
if mods:
|
591 |
+
sequence_parts.append(f"{residue}({','.join(mods)})")
|
592 |
+
else:
|
593 |
+
sequence_parts.append(residue)
|
594 |
+
output_text += f"Identified as: {residue}\n"
|
595 |
+
output_text += f"Modifications: {mods}\n"
|
596 |
else:
|
597 |
+
output_text += f"Warning: Could not identify residue in segment: {segment['content']}\n"
|
598 |
+
output_text += "\n"
|
599 |
+
else:
|
600 |
+
# Just build sequence without detailed analysis in output
|
601 |
+
for segment in segments:
|
602 |
+
residue, mods = analyzer.identify_residue(segment)
|
603 |
+
if residue:
|
604 |
+
if mods:
|
605 |
+
sequence_parts.append(f"{residue}({','.join(mods)})")
|
606 |
+
else:
|
607 |
+
sequence_parts.append(residue)
|
608 |
|
609 |
# Check if cyclic using analyzer's method
|
610 |
is_cyclic, peptide_cycles, aromatic_cycles = analyzer.is_cyclic(smiles)
|
|
|
624 |
plt.close(fig_linear)
|
625 |
|
626 |
# Add summary to output
|
627 |
+
summary = "Summary:\n"
|
628 |
summary += f"Sequence: {sequence}\n"
|
629 |
summary += f"Is Cyclic: {'Yes' if is_cyclic else 'No'}\n"
|
630 |
if is_cyclic:
|
631 |
summary += f"Peptide Cycles: {', '.join(peptide_cycles)}\n"
|
632 |
summary += f"Aromatic Cycles: {', '.join(aromatic_cycles)}\n"
|
633 |
|
634 |
+
return summary + output_text, img_cyclic, img_linear
|
635 |
|
636 |
except Exception as e:
|
637 |
return f"Error processing SMILES: {str(e)}", None, None
|
|
|
658 |
# Process this SMILES
|
659 |
segments = analyzer.split_on_bonds(smiles)
|
660 |
sequence_parts = []
|
661 |
+
|
662 |
+
# Add segment details if requested
|
663 |
+
if show_segment_details:
|
664 |
+
output_text += f"\nSegment Analysis for SMILES: {smiles}\n"
|
665 |
+
for i, segment in enumerate(segments):
|
666 |
+
output_text += f"\nSegment {i}:\n"
|
667 |
+
output_text += f"Content: {segment['content']}\n"
|
668 |
+
output_text += f"Bond before: {segment.get('bond_before', 'None')}\n"
|
669 |
+
output_text += f"Bond after: {segment.get('bond_after', 'None')}\n"
|
670 |
+
residue, mods = analyzer.identify_residue(segment)
|
671 |
+
if residue:
|
672 |
+
if mods:
|
673 |
+
sequence_parts.append(f"{residue}({','.join(mods)})")
|
674 |
+
else:
|
675 |
+
sequence_parts.append(residue)
|
676 |
+
output_text += f"Identified as: {residue}\n"
|
677 |
+
output_text += f"Modifications: {mods}\n"
|
678 |
+
else:
|
679 |
+
for segment in segments:
|
680 |
+
residue, mods = analyzer.identify_residue(segment)
|
681 |
+
if residue:
|
682 |
+
if mods:
|
683 |
+
sequence_parts.append(f"{residue}({','.join(mods)})")
|
684 |
+
else:
|
685 |
+
sequence_parts.append(residue)
|
686 |
|
687 |
# Get cyclicity and create sequence
|
688 |
is_cyclic, peptide_cycles, aromatic_cycles = analyzer.is_cyclic(smiles)
|
689 |
sequence = f"cyclo({'-'.join(sequence_parts)})" if is_cyclic else '-'.join(sequence_parts)
|
690 |
|
691 |
+
output_text += f"\nSummary for SMILES: {smiles}\n"
|
692 |
output_text += f"Sequence: {sequence}\n"
|
693 |
output_text += f"Is Cyclic: {'Yes' if is_cyclic else 'No'}\n"
|
694 |
if is_cyclic:
|
|
|
705 |
|
706 |
iface = gr.Interface(
|
707 |
fn=process_input,
|
708 |
+
iinputs=[
|
709 |
+
gr.Textbox(label="Enter SMILES string", placeholder="Enter SMILES notation of peptide...", lines=2),
|
710 |
+
gr.File(label="Or upload a text file with SMILES", file_types=[".txt"], type="binary"),
|
711 |
+
gr.Checkbox(label="Show linear representation"),
|
712 |
+
gr.Checkbox(label="Show segment details") # New checkbox for segment details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
713 |
],
|
714 |
outputs=[
|
715 |
+
gr.Textbox(label="Analysis Results", lines=10),
|
716 |
+
gr.Image(label="2D Structure with Annotations"),
|
717 |
+
gr.Image(label="Linear Representation")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
718 |
],
|
719 |
title="Peptide Structure Analyzer and Visualizer",
|
720 |
description="""
|