wenjun99 commited on
Commit
ff7c33d
·
verified ·
1 Parent(s): 89360a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -98
app.py CHANGED
@@ -393,7 +393,7 @@ with tab5:
393
  st.header("Decode Binary Labels to String")
394
 
395
  # Utility: Track source volumes and update if exceeds limit
396
- def track_and_replace_source(source_list, robot_script, volume_limit=170):
397
  source_volumes = {}
398
  adjusted_sources = []
399
 
@@ -461,11 +461,10 @@ with tab5:
461
  wells.append(f"{row}{col}")
462
  return wells
463
 
464
- # ========== 32-BIT DECODING ==========
465
- st.subheader("32-bit Binary per Row")
466
- st.write("Upload CSV with 32 columns (0 or 1), no headers, from EF Binary format or enter manually below.")
467
 
468
- binary32_file = st.file_uploader("Upload 32-bit Binary CSV", type=["csv"], key="binary_32")
469
 
470
  st.subheader("Optional Metadata (Optional)")
471
  barcode_id_input = st.text_input("Barcode ID (applied to all rows, optional)", value="")
@@ -475,36 +474,25 @@ with tab5:
475
 
476
  if binary32_file:
477
  df_32 = pd.read_csv(binary32_file, header=None)
478
- df_32.columns = [str(h) for h in mutation_site_headers_actual_3614]
479
  else:
480
  df_32 = st.data_editor(
481
- pd.DataFrame(columns=[str(h) for h in mutation_site_headers_actual_3614]),
482
  num_rows="dynamic",
483
- key="manual_32_input"
484
  )
485
 
486
  if not df_32.empty:
487
- reordered_df_32 = df_32[[str(h) for h in mutation_site_headers_3614 if str(h) in df_32.columns]]
488
- st.subheader("Binary Labels (Reordered 4402→3244, 4882→4455)")
489
- st.dataframe(reordered_df_32.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
490
- st.download_button("Download Reordered CSV", reordered_df_32.to_csv(index=False), "decoded_binary_32_reordered.csv", key="download_csv_tab5_32_reordered")
491
-
492
- decoded_reordered = binary_labels_to_string(reordered_df_32.values.flatten().astype(int).tolist())
493
- st.subheader("Decoded String (Reordered 4402→3244, 4882→4455)")
494
- st.write(decoded_reordered)
495
- st.download_button("Download Concatenated Output", decoded_reordered, "decoded_32bit_string_reordered.txt", key="download_txt_tab5_32")
496
 
497
- df_32_asc = df_32[[str(h) for h in mutation_site_headers_actual_3614 if str(h) in df_32.columns]]
498
- st.subheader("Binary Labels (Ascending 3244→4882)")
499
- st.dataframe(df_32_asc.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
500
- st.download_button("Download Ascending CSV", df_32_asc.to_csv(index=False), "decoded_binary_32_ascending.csv", key="download_csv_tab5_32_ascend")
501
 
502
- decoded_asc = binary_labels_to_string(df_32_asc.values.flatten().astype(int).tolist())
503
- st.subheader("Decoded String (Flattened 32-bit Ascending)")
504
- st.write(decoded_asc)
505
- st.download_button("Download Concatenated Output", decoded_asc, "decoded_32bit_string_ascending.txt", key="download_txt_tab5_32_asc")
506
-
507
- st.subheader("Robot Preparation Script from 32-bit Binary")
508
 
509
  df_32_robot = df_32.copy()
510
  df_32_robot.insert(0, 'Sample', range(1, len(df_32_robot)+1))
@@ -513,14 +501,12 @@ with tab5:
513
 
514
  robot_script_32 = []
515
  source_wells_32 = generate_source_wells(df_32.shape[1])
516
- used_destinations = set()
517
 
518
  for i, col in enumerate(df_32.columns):
519
  for row_idx, sample in df_32_robot.iterrows():
520
  if int(sample[col]) == 1:
521
  source = source_wells_32[i]
522
  dest = get_well_position(int(sample['Sample']))
523
- used_destinations.add(dest)
524
  vol = round(sample['volume donors (µl)'], 2)
525
  tool = 'TS_10' if vol < 10 else 'TS_50'
526
  robot_script_32.append({
@@ -543,77 +529,10 @@ with tab5:
543
  robot_script_32_df = robot_script_32_df[['Barcode ID', 'Labware_Source', 'Source', 'Labware_Destination', 'Destination', 'Volume', 'Tool', 'Name']]
544
 
545
  st.dataframe(robot_script_32_df)
546
- st.download_button("Download Robot Script (32-bit)", robot_script_32_df.to_csv(index=False), "robot_script_32bit.csv", key="download_robot_32")
547
 
548
  st.subheader("Total Volume Used Per Source")
549
  combined_volumes = {**source_volumes_32, **d_volumes}
550
  source_volume_df = pd.DataFrame(list(combined_volumes.items()), columns=['Source', 'Total Volume (µl)'])
551
  st.dataframe(source_volume_df)
552
- st.download_button("Download Source Volumes", source_volume_df.to_csv(index=False), "source_total_volumes.csv", key="download_volume_32")
553
-
554
- st.markdown("---")
555
-
556
- # ========== 31-BIT DECODING ==========
557
- st.subheader("31-bit Binary Grouped per Row")
558
- st.write("Upload CSV with 31 columns (no headers), each row = one 6-bit ASCII character group or enter manually below.")
559
-
560
- binary31_file = st.file_uploader("Upload 31-bit Group CSV", type=["csv"], key="binary_31")
561
-
562
- if binary31_file:
563
- df_31 = pd.read_csv(binary31_file, header=None)
564
- df_31.columns = [str(h) for h in mutation_site_headers_actual] # assume ascending
565
- else:
566
- df_31 = st.data_editor(
567
- pd.DataFrame(columns=[str(h) for h in mutation_site_headers_actual]),
568
- num_rows="dynamic",
569
- key="manual_31_input"
570
- )
571
-
572
- if not df_31.empty:
573
- reordered_df_31 = df_31[[str(h) for h in mutation_site_headers if str(h) in df_31.columns]]
574
- st.subheader("Binary Labels (Reordered 4402→3244, 4882→4455)")
575
- st.dataframe(reordered_df_31.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
576
- st.download_button("Download Reordered CSV", reordered_df_31.to_csv(index=False), "decoded_binary_31_reordered.csv", key="download_csv_tab5_31_reordered")
577
-
578
- decoded_flat_reordered = binary_labels_to_string(reordered_df_31.values.flatten().astype(int).tolist())
579
- st.subheader("Decoded String (Flattened 31-bit Reordered)")
580
- st.write(decoded_flat_reordered)
581
- st.download_button("Download Concatenated Output", decoded_flat_reordered, "decoded_31bit_string_reordered.txt", key="download_csv_tab5_31")
582
-
583
- df_31_asc = df_31[[str(h) for h in mutation_site_headers_actual if str(h) in df_31.columns]]
584
- st.subheader("Binary Labels (Ascending 3244→4882)")
585
- st.dataframe(df_31_asc.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
586
- st.download_button("Download Ascending CSV", df_31_asc.to_csv(index=False), "decoded_binary_31_ascending.csv", key="download_csv_tab5_31_ascend")
587
-
588
- decoded_flat_asc = binary_labels_to_string(df_31_asc.values.flatten().astype(int).tolist())
589
- st.subheader("Decoded String (Flattened 31-bit Ascending)")
590
- st.write(decoded_flat_asc)
591
- st.download_button("Download Concatenated Output", decoded_flat_asc, "decoded_31bit_string_ascending.txt", key="download_csv_tab5_31_asc")
592
-
593
- # === Robot Preparation Script from 31-bit Binary ===
594
- st.subheader("Robot Preparation Script from 31-bit Binary")
595
- robot_template_31 = pd.read_csv("/home/user/app/Robot2.csv", skiprows=3)
596
- robot_template_31.columns = ['Labware', 'Source', 'Labware_2', 'Destination', 'Volume', 'Tool', 'Name']
597
-
598
- df_31_robot = df_31.copy()
599
- df_31_robot.insert(0, 'Sample', range(1, len(df_31_robot)+1))
600
- df_31_robot['# donors'] = df_31_robot.iloc[:, 1:].astype(int).sum(axis=1)
601
- df_31_robot['volume donors (µl)'] = 64 / df_31_robot['# donors']
602
-
603
- robot_script_31 = []
604
- source_wells_31 = robot_template_31['Source'].unique().tolist()
605
- if len(source_wells_31) < df_31.shape[1]:
606
- source_wells_31 += [f"Fake{i}" for i in range(df_31.shape[1] - len(source_wells_31))]
607
- source_wells_31 = source_wells_31[:df_31.shape[1]]
608
-
609
- for i, col in enumerate(df_31.columns):
610
- for row_idx, sample in df_31_robot.iterrows():
611
- if int(sample[col]) == 1:
612
- source = source_wells_31[i]
613
- dest = get_well_position(int(sample['Sample']))
614
- vol = round(sample['volume donors (µl)'], 2)
615
- robot_script_31.append({'Source': source, 'Destination': dest, 'Volume': vol})
616
-
617
- robot_script_31_df = pd.DataFrame(robot_script_31)
618
- st.dataframe(robot_script_31_df)
619
- st.download_button("Download Robot Script (31-bit)", robot_script_31_df.to_csv(index=False), "robot_script_31bit.csv", key="download_robot_31")
 
393
  st.header("Decode Binary Labels to String")
394
 
395
  # Utility: Track source volumes and update if exceeds limit
396
+ def track_and_replace_source(source_list, robot_script, volume_limit=180):
397
  source_volumes = {}
398
  adjusted_sources = []
399
 
 
461
  wells.append(f"{row}{col}")
462
  return wells
463
 
464
+ st.subheader("Binary per Row")
465
+ st.write("Upload CSV with any number of columns (0 or 1), no headers, from EF Binary format or enter manually below.")
 
466
 
467
+ binary32_file = st.file_uploader("Upload Binary CSV", type=["csv"], key="binary_any")
468
 
469
  st.subheader("Optional Metadata (Optional)")
470
  barcode_id_input = st.text_input("Barcode ID (applied to all rows, optional)", value="")
 
474
 
475
  if binary32_file:
476
  df_32 = pd.read_csv(binary32_file, header=None)
477
+ df_32.columns = [str(h) for h in range(1, len(df_32.columns)+1)]
478
  else:
479
  df_32 = st.data_editor(
480
+ pd.DataFrame(columns=[str(h) for h in range(1, 33)]),
481
  num_rows="dynamic",
482
+ key="manual_any_input"
483
  )
484
 
485
  if not df_32.empty:
486
+ st.subheader("Binary Labels (Uploaded)")
487
+ st.dataframe(df_32.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
488
+ st.download_button("Download CSV", df_32.to_csv(index=False), "decoded_binary_uploaded.csv", key="download_csv_uploaded")
 
 
 
 
 
 
489
 
490
+ decoded = binary_labels_to_string(df_32.values.flatten().astype(int).tolist())
491
+ st.subheader("Decoded String")
492
+ st.write(decoded)
493
+ st.download_button("Download Concatenated Output", decoded, "decoded_binary_string.txt", key="download_txt_any")
494
 
495
+ st.subheader("Robot Preparation Script from Binary")
 
 
 
 
 
496
 
497
  df_32_robot = df_32.copy()
498
  df_32_robot.insert(0, 'Sample', range(1, len(df_32_robot)+1))
 
501
 
502
  robot_script_32 = []
503
  source_wells_32 = generate_source_wells(df_32.shape[1])
 
504
 
505
  for i, col in enumerate(df_32.columns):
506
  for row_idx, sample in df_32_robot.iterrows():
507
  if int(sample[col]) == 1:
508
  source = source_wells_32[i]
509
  dest = get_well_position(int(sample['Sample']))
 
510
  vol = round(sample['volume donors (µl)'], 2)
511
  tool = 'TS_10' if vol < 10 else 'TS_50'
512
  robot_script_32.append({
 
529
  robot_script_32_df = robot_script_32_df[['Barcode ID', 'Labware_Source', 'Source', 'Labware_Destination', 'Destination', 'Volume', 'Tool', 'Name']]
530
 
531
  st.dataframe(robot_script_32_df)
532
+ st.download_button("Download Robot Script", robot_script_32_df.to_csv(index=False), "robot_script.csv", key="download_robot_any")
533
 
534
  st.subheader("Total Volume Used Per Source")
535
  combined_volumes = {**source_volumes_32, **d_volumes}
536
  source_volume_df = pd.DataFrame(list(combined_volumes.items()), columns=['Source', 'Total Volume (µl)'])
537
  st.dataframe(source_volume_df)
538
+ st.download_button("Download Source Volumes", source_volume_df.to_csv(index=False), "source_total_volumes.csv", key="download_volume_any")