yinuozhang commited on
Commit
809cdad
·
1 Parent(s): a0d49a3
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -117,8 +117,7 @@ class PeptideAnalyzer:
117
  'content': complex_part
118
  })
119
 
120
- # Debug
121
- print(f"Protected {pos['type']}: {complex_part[:20]}... as {placeholder}")
122
 
123
  return preprocessed_smiles, protected_residues
124
  def split_on_bonds(self, smiles, protected_residues=None):
@@ -574,16 +573,16 @@ class PeptideAnalyzer:
574
 
575
  def analyze_structure(self, smiles):
576
  """Main analysis function with preprocessing for complex residues"""
577
- print("\nAnalyzing structure:", smiles)
578
 
579
  # Pre-process to identify complex residues first
580
  preprocessed_smiles, protected_residues = self.preprocess_complex_residues(smiles)
581
-
582
  if protected_residues:
583
  print(f"Identified {len(protected_residues)} complex residues during pre-processing")
584
  for i, residue in enumerate(protected_residues):
585
  print(f"Complex residue {i+1}: {residue['type']}")
586
-
587
 
588
  # Check if it's cyclic
589
  is_cyclic, peptide_cycles, aromatic_cycles = self.is_cyclic(smiles)
@@ -591,22 +590,24 @@ class PeptideAnalyzer:
591
  # Split into segments, respecting protected residues
592
  segments = self.split_on_bonds(preprocessed_smiles, protected_residues)
593
 
594
- print("\nSegment Analysis:")
595
  sequence = []
596
  for i, segment in enumerate(segments):
 
597
  print(f"\nSegment {i}:")
598
  print(f"Content: {segment.get('content', 'None')}")
599
  print(f"Bond before: {segment.get('bond_before', 'None')}")
600
  print(f"Bond after: {segment.get('bond_after', 'None')}")
601
-
602
  residue, mods = self.identify_residue(segment)
603
  if residue:
604
  if mods:
605
  sequence.append(f"{residue}({','.join(mods)})")
606
  else:
607
  sequence.append(residue)
608
- print(f"Identified as: {residue}")
609
- print(f"Modifications: {mods}")
 
610
  else:
611
  print(f"Warning: Could not identify residue in segment: {segment.get('content', 'None')}")
612
 
@@ -619,13 +620,13 @@ class PeptideAnalyzer:
619
  if is_cyclic:
620
  three_letter = f"cyclo({three_letter})"
621
  one_letter = f"cyclo({one_letter})"
622
-
623
  print(f"\nFinal sequence: {three_letter}")
624
  print(f"One-letter code: {one_letter}")
625
  print(f"Is cyclic: {is_cyclic}")
626
  print(f"Peptide cycles: {peptide_cycles}")
627
  print(f"Aromatic cycles: {aromatic_cycles}")
628
-
629
  return {
630
  'three_letter': three_letter,
631
  'one_letter': one_letter,
@@ -994,11 +995,12 @@ def process_input(
994
  for filepath in structure_files:
995
  summary += f"- {os.path.basename(filepath)}\n"
996
 
997
- return summary, img_cyclic, img_linear, structure_files if structure_files else None
998
-
 
999
  except Exception as e:
1000
- return f"Error processing SMILES: {str(e)}", None, None, []
1001
-
1002
  # Handle file input
1003
  if file_obj is not None:
1004
  try:
@@ -1055,6 +1057,7 @@ iface = gr.Interface(
1055
  label="Or upload a text file with SMILES",
1056
  file_types=[".txt"]
1057
  ),
 
1058
  gr.Checkbox(
1059
  label="Show linear representation",
1060
  value=False
@@ -1071,6 +1074,7 @@ iface = gr.Interface(
1071
  label="Use UFF optimization (may take long)",
1072
  value=False
1073
  )
 
1074
  ],
1075
  outputs=[
1076
  gr.Textbox(
@@ -1081,6 +1085,7 @@ iface = gr.Interface(
1081
  label="2D Structure with Annotations",
1082
  type="pil"
1083
  ),
 
1084
  gr.Image(
1085
  label="Linear Representation",
1086
  type="pil"
@@ -1088,7 +1093,7 @@ iface = gr.Interface(
1088
  gr.File(
1089
  label="3D Structure Files",
1090
  file_count="multiple"
1091
- )
1092
  ],
1093
  title="Peptide Structure Analyzer and Visualizer",
1094
  description="""
 
117
  'content': complex_part
118
  })
119
 
120
+ #print(f"Protected {pos['type']}: {complex_part[:20]}... as {placeholder}")
 
121
 
122
  return preprocessed_smiles, protected_residues
123
  def split_on_bonds(self, smiles, protected_residues=None):
 
573
 
574
  def analyze_structure(self, smiles):
575
  """Main analysis function with preprocessing for complex residues"""
576
+ #print("\nAnalyzing structure:", smiles)
577
 
578
  # Pre-process to identify complex residues first
579
  preprocessed_smiles, protected_residues = self.preprocess_complex_residues(smiles)
580
+ """
581
  if protected_residues:
582
  print(f"Identified {len(protected_residues)} complex residues during pre-processing")
583
  for i, residue in enumerate(protected_residues):
584
  print(f"Complex residue {i+1}: {residue['type']}")
585
+ """
586
 
587
  # Check if it's cyclic
588
  is_cyclic, peptide_cycles, aromatic_cycles = self.is_cyclic(smiles)
 
590
  # Split into segments, respecting protected residues
591
  segments = self.split_on_bonds(preprocessed_smiles, protected_residues)
592
 
593
+ #print("\nSegment Analysis:")
594
  sequence = []
595
  for i, segment in enumerate(segments):
596
+ """
597
  print(f"\nSegment {i}:")
598
  print(f"Content: {segment.get('content', 'None')}")
599
  print(f"Bond before: {segment.get('bond_before', 'None')}")
600
  print(f"Bond after: {segment.get('bond_after', 'None')}")
601
+ """
602
  residue, mods = self.identify_residue(segment)
603
  if residue:
604
  if mods:
605
  sequence.append(f"{residue}({','.join(mods)})")
606
  else:
607
  sequence.append(residue)
608
+
609
+ #print(f"Identified as: {residue}")
610
+ #print(f"Modifications: {mods}")
611
  else:
612
  print(f"Warning: Could not identify residue in segment: {segment.get('content', 'None')}")
613
 
 
620
  if is_cyclic:
621
  three_letter = f"cyclo({three_letter})"
622
  one_letter = f"cyclo({one_letter})"
623
+ """
624
  print(f"\nFinal sequence: {three_letter}")
625
  print(f"One-letter code: {one_letter}")
626
  print(f"Is cyclic: {is_cyclic}")
627
  print(f"Peptide cycles: {peptide_cycles}")
628
  print(f"Aromatic cycles: {aromatic_cycles}")
629
+ """
630
  return {
631
  'three_letter': three_letter,
632
  'one_letter': one_letter,
 
995
  for filepath in structure_files:
996
  summary += f"- {os.path.basename(filepath)}\n"
997
 
998
+ #return summary, img_cyclic, img_linear, structure_files if structure_files else None
999
+ return summary, img_cyclic
1000
+
1001
  except Exception as e:
1002
+ #return f"Error processing SMILES: {str(e)}", None, None, []
1003
+ return f"Error processing SMILES: {str(e)}", None
1004
  # Handle file input
1005
  if file_obj is not None:
1006
  try:
 
1057
  label="Or upload a text file with SMILES",
1058
  file_types=[".txt"]
1059
  ),
1060
+ """
1061
  gr.Checkbox(
1062
  label="Show linear representation",
1063
  value=False
 
1074
  label="Use UFF optimization (may take long)",
1075
  value=False
1076
  )
1077
+ """
1078
  ],
1079
  outputs=[
1080
  gr.Textbox(
 
1085
  label="2D Structure with Annotations",
1086
  type="pil"
1087
  ),
1088
+ """
1089
  gr.Image(
1090
  label="Linear Representation",
1091
  type="pil"
 
1093
  gr.File(
1094
  label="3D Structure Files",
1095
  file_count="multiple"
1096
+ )"""
1097
  ],
1098
  title="Peptide Structure Analyzer and Visualizer",
1099
  description="""