supercat666 commited on
Commit
c2e36d2
1 Parent(s): a16f85c

fix button

Browse files
Files changed (1) hide show
  1. app.py +30 -25
app.py CHANGED
@@ -495,31 +495,36 @@ elif selected_model == 'Cas12':
495
  ('regular', 'mutation'),
496
  key='cas12target_selection'
497
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
498
  # Gene symbol entry with autocomplete-like feature
499
  gene_symbol = st.selectbox('Enter a Gene Symbol:', [''] + gene_symbol_list, key='gene_symbol',
500
  format_func=lambda x: x if x else "")
501
 
502
- # Initialize the current_gene_symbol in the session state if it doesn't exist
503
- if 'current_gene_symbol' not in st.session_state:
504
- st.session_state['current_gene_symbol'] = ""
 
 
 
 
505
 
506
  if cas12target_selection == 'regular':
507
- # Prediction button
508
- predict_button = st.button('Predict')
509
-
510
- # Function to clean up old files
511
- def clean_up_old_files(gene_symbol):
512
- genbank_file_path = f"{gene_symbol}_crispr_targets.gb"
513
- bed_file_path = f"{gene_symbol}_crispr_targets.bed"
514
- csv_file_path = f"{gene_symbol}_crispr_predictions.csv"
515
- for path in [genbank_file_path, bed_file_path, csv_file_path]:
516
- if os.path.exists(path):
517
- os.remove(path)
518
-
519
 
520
- # Clean up files if a new gene symbol is entered
521
- if st.session_state['current_gene_symbol'] and gene_symbol != st.session_state['current_gene_symbol']:
522
- clean_up_old_files(st.session_state['current_gene_symbol'])
523
 
524
  # Process predictions
525
  if predict_button and gene_symbol:
@@ -546,12 +551,12 @@ elif selected_model == 'Cas12':
546
  with col3:
547
  st.markdown("**Nuclease**")
548
  st.markdown("SpCas9")
549
- # Include "Target" in the DataFrame's columns
550
  try:
551
  df = pd.DataFrame(st.session_state['on_target_results'],
552
- columns=["Chr", "Start Pos", "End Pos", "Strand", "Transcript", "Exon",
553
- "Target",
554
- "gRNA", "Prediction"])
555
  st.dataframe(df)
556
  except ValueError as e:
557
  st.error(f"DataFrame creation error: {e}")
@@ -564,7 +569,7 @@ elif selected_model == 'Cas12':
564
  EXON_BASE = 0 # Base position for exons and CDS on the Y axis
565
  EXON_HEIGHT = 0.02 # How 'tall' the exon markers should appear
566
 
567
- # Plot Exons as small markers on the X-axis
568
  for exon in st.session_state['exons']:
569
  exon_start, exon_end = exon['start'], exon['end']
570
  fig.add_trace(go.Bar(
@@ -596,7 +601,7 @@ elif selected_model == 'Cas12':
596
  y=[y_value],
597
  mode='markers+text',
598
  marker=dict(symbol='triangle-up' if strand == '1' or strand == '+' else 'triangle-down',
599
- size=12),
600
  text=f"Rank: {i}", # Text label
601
  hoverinfo='text',
602
  hovertext=f"Rank: {i}<br>Chromosome: {chrom}<br>Target Sequence: {target}<br>gRNA: {gRNA}<br>Start: {start}<br>End: {end}<br>Strand: {'+' if strand == '1' or strand == '+' else '-'}<br>Transcript: {transcript}<br>Prediction: {prediction_score:.4f}",
@@ -661,7 +666,7 @@ elif selected_model == 'Cas12':
661
  )
662
  elif cas12target_selection == 'mutation':
663
  # Prediction button
664
- predict_button = st.button('Predict')
665
  vcf_reader = cyvcf2.VCF('SRR25934512.filter.snps.indels.vcf.gz')
666
 
667
  if 'exons' not in st.session_state:
 
495
  ('regular', 'mutation'),
496
  key='cas12target_selection'
497
  )
498
+ if 'current_gene_symbol' not in st.session_state:
499
+ st.session_state['current_gene_symbol'] = ""
500
+
501
+ # Define a function to clean up old files
502
+
503
+ def clean_up_old_files(gene_symbol):
504
+ genbank_file_path = f"{gene_symbol}_crispr_targets.gb"
505
+ bed_file_path = f"{gene_symbol}_crispr_targets.bed"
506
+ csv_file_path = f"{gene_symbol}_crispr_predictions.csv"
507
+ for path in [genbank_file_path, bed_file_path, csv_file_path]:
508
+ if os.path.exists(path):
509
+ os.remove(path)
510
+
511
  # Gene symbol entry with autocomplete-like feature
512
  gene_symbol = st.selectbox('Enter a Gene Symbol:', [''] + gene_symbol_list, key='gene_symbol',
513
  format_func=lambda x: x if x else "")
514
 
515
+ # Handle gene symbol change and file cleanup
516
+ if gene_symbol != st.session_state['current_gene_symbol'] and gene_symbol:
517
+ if st.session_state['current_gene_symbol']:
518
+ # Clean up files only if a different gene symbol is entered and a previous symbol exists
519
+ clean_up_old_files(st.session_state['current_gene_symbol'])
520
+ # Update the session state with the new gene symbol
521
+ st.session_state['current_gene_symbol'] = gene_symbol
522
 
523
  if cas12target_selection == 'regular':
524
+ predict_button = st.button('Predict cas12')
 
 
 
 
 
 
 
 
 
 
 
525
 
526
+ if 'exons' not in st.session_state:
527
+ st.session_state['exons'] = []
 
528
 
529
  # Process predictions
530
  if predict_button and gene_symbol:
 
551
  with col3:
552
  st.markdown("**Nuclease**")
553
  st.markdown("SpCas9")
554
+ # Include "Target" in the DataFrame's columns
555
  try:
556
  df = pd.DataFrame(st.session_state['on_target_results'],
557
+ columns=["Chr", "Start Pos", "End Pos", "Strand", "Transcript", "Exon",
558
+ "Target",
559
+ "gRNA", "Prediction"])
560
  st.dataframe(df)
561
  except ValueError as e:
562
  st.error(f"DataFrame creation error: {e}")
 
569
  EXON_BASE = 0 # Base position for exons and CDS on the Y axis
570
  EXON_HEIGHT = 0.02 # How 'tall' the exon markers should appear
571
 
572
+ # Plot Exons as small markers on the X-axis
573
  for exon in st.session_state['exons']:
574
  exon_start, exon_end = exon['start'], exon['end']
575
  fig.add_trace(go.Bar(
 
601
  y=[y_value],
602
  mode='markers+text',
603
  marker=dict(symbol='triangle-up' if strand == '1' or strand == '+' else 'triangle-down',
604
+ size=12),
605
  text=f"Rank: {i}", # Text label
606
  hoverinfo='text',
607
  hovertext=f"Rank: {i}<br>Chromosome: {chrom}<br>Target Sequence: {target}<br>gRNA: {gRNA}<br>Start: {start}<br>End: {end}<br>Strand: {'+' if strand == '1' or strand == '+' else '-'}<br>Transcript: {transcript}<br>Prediction: {prediction_score:.4f}",
 
666
  )
667
  elif cas12target_selection == 'mutation':
668
  # Prediction button
669
+ predict_button = st.button('Predict cas12')
670
  vcf_reader = cyvcf2.VCF('SRR25934512.filter.snps.indels.vcf.gz')
671
 
672
  if 'exons' not in st.session_state: