wenjun99 commited on
Commit
7795a77
Β·
verified Β·
1 Parent(s): 4731aa2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -388,21 +388,27 @@ def get_well_position(sample_index):
388
  col_number = ((sample_index - 1) % 12) + 1
389
  return f"{row_letter}{col_number}"
390
 
391
-
392
  # Tab 5: Binary β†’ String
393
  with tab5:
394
  st.header("Decode Binary Labels to String")
395
 
396
  # ========== 32-BIT DECODING ==========
397
  st.subheader("32-bit Binary per Row")
398
- st.write("Upload CSV with 32 columns (0 or 1), no headers, from EF Binary format.")
 
399
  binary32_file = st.file_uploader("Upload 32-bit Binary CSV", type=["csv"], key="binary_32")
400
 
401
  if binary32_file:
402
  df_32 = pd.read_csv(binary32_file, header=None)
403
  df_32.columns = [str(h) for h in mutation_site_headers_actual_3614] # assume ascending
 
 
 
 
 
 
404
 
405
- # Reordered: 4402 β†’ 3244, 4882 β†’ 4455
406
  reordered_df_32 = df_32[[str(h) for h in mutation_site_headers_3614 if str(h) in df_32.columns]]
407
  st.subheader("Binary Labels (Reordered 4402β†’3244, 4882β†’4455)")
408
  st.dataframe(reordered_df_32.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
@@ -412,7 +418,6 @@ with tab5:
412
  st.subheader("Decoded String (Reordered 4402β†’3244, 4882β†’4455)")
413
  st.write(decoded_reordered)
414
 
415
- # Ascending: 3244 β†’ 4882
416
  df_ascending = df_32[[str(h) for h in mutation_site_headers_actual_3614 if str(h) in df_32.columns]]
417
  st.subheader("Binary Labels (Ascending 3244β†’4882)")
418
  st.dataframe(df_ascending.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
@@ -442,7 +447,7 @@ with tab5:
442
  for row_idx, sample in df_32_robot.iterrows():
443
  if sample[col] == 1:
444
  source = source_wells_32[i]
445
- dest = f"A{sample['Sample']}"
446
  vol = round(sample['volume donors (Β΅l)'], 2)
447
  robot_script_32.append({'Source': source, 'Destination': dest, 'Volume': vol})
448
 
@@ -450,42 +455,45 @@ with tab5:
450
  st.dataframe(robot_script_32_df)
451
  st.download_button("Download Robot Script (32-bit)", robot_script_32_df.to_csv(index=False), "robot_script_32bit.csv", key="download_robot_32")
452
 
453
-
454
  st.markdown("---")
455
 
456
  # ========== 31-BIT DECODING ==========
457
  st.subheader("31-bit Binary Grouped per Row")
458
- st.write("Upload CSV with 31 columns (no headers), each row = one 6-bit ASCII character group.")
459
 
460
  binary31_file = st.file_uploader("Upload 31-bit Group CSV", type=["csv"], key="binary_31")
 
461
  if binary31_file:
462
  df_31 = pd.read_csv(binary31_file, header=None)
463
  df_31.columns = [str(h) for h in mutation_site_headers_actual] # assume ascending
 
 
 
 
 
 
464
 
465
- # Reordered: 4402 β†’ 3244, 4882 β†’ 4455
466
  reordered_df_31 = df_31[[str(h) for h in mutation_site_headers if str(h) in df_31.columns]]
467
  st.subheader("Binary Labels (Reordered 4402β†’3244, 4882β†’4455)")
468
  st.dataframe(reordered_df_31.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
469
  st.download_button("Download Reordered CSV", reordered_df_31.to_csv(index=False), "decoded_binary_31_reordered.csv", key="download_csv_tab5_31_reordered")
470
 
471
- # Flattened decoding for reordered
472
  decoded_flat_reordered = binary_labels_to_string(reordered_df_31.values.flatten().astype(int).tolist())
473
  st.subheader("Decoded String (Flattened 31-bit Reordered)")
474
  st.write(decoded_flat_reordered)
475
  st.download_button("Download Concatenated Output", decoded_flat_reordered, "decoded_31bit_string_reordered.txt", key="download_csv_tab5_31")
476
 
477
- # Ascending: 3244 β†’ 4882
478
  df_31_asc = df_31[[str(h) for h in mutation_site_headers_actual if str(h) in df_31.columns]]
479
  st.subheader("Binary Labels (Ascending 3244β†’4882)")
480
  st.dataframe(df_31_asc.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
481
  st.download_button("Download Ascending CSV", df_31_asc.to_csv(index=False), "decoded_binary_31_ascending.csv", key="download_csv_tab5_31_ascend")
482
 
483
- # Flattened decoding for ascending
484
  decoded_flat_asc = binary_labels_to_string(df_31_asc.values.flatten().astype(int).tolist())
485
  st.subheader("Decoded String (Flattened 31-bit Ascending)")
486
  st.write(decoded_flat_asc)
487
  st.download_button("Download Concatenated Output", decoded_flat_asc, "decoded_31bit_string_ascending.txt", key="download_csv_tab5_31_asc")
488
-
489
  # === Robot Preparation Script from 31-bit Binary ===
490
  st.subheader("Robot Preparation Script from 31-bit Binary")
491
  robot_template_31 = pd.read_csv("/home/user/app/Robot2.csv", skiprows=3)
 
388
  col_number = ((sample_index - 1) % 12) + 1
389
  return f"{row_letter}{col_number}"
390
 
 
391
  # Tab 5: Binary β†’ String
392
  with tab5:
393
  st.header("Decode Binary Labels to String")
394
 
395
  # ========== 32-BIT DECODING ==========
396
  st.subheader("32-bit Binary per Row")
397
+ st.write("Upload CSV with 32 columns (0 or 1), no headers, from EF Binary format or enter manually below.")
398
+
399
  binary32_file = st.file_uploader("Upload 32-bit Binary CSV", type=["csv"], key="binary_32")
400
 
401
  if binary32_file:
402
  df_32 = pd.read_csv(binary32_file, header=None)
403
  df_32.columns = [str(h) for h in mutation_site_headers_actual_3614] # assume ascending
404
+ else:
405
+ df_32 = st.data_editor(
406
+ pd.DataFrame(columns=[str(h) for h in mutation_site_headers_actual_3614]),
407
+ num_rows="dynamic",
408
+ key="manual_32_input"
409
+ )
410
 
411
+ if not df_32.empty:
412
  reordered_df_32 = df_32[[str(h) for h in mutation_site_headers_3614 if str(h) in df_32.columns]]
413
  st.subheader("Binary Labels (Reordered 4402β†’3244, 4882β†’4455)")
414
  st.dataframe(reordered_df_32.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
 
418
  st.subheader("Decoded String (Reordered 4402β†’3244, 4882β†’4455)")
419
  st.write(decoded_reordered)
420
 
 
421
  df_ascending = df_32[[str(h) for h in mutation_site_headers_actual_3614 if str(h) in df_32.columns]]
422
  st.subheader("Binary Labels (Ascending 3244β†’4882)")
423
  st.dataframe(df_ascending.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
 
447
  for row_idx, sample in df_32_robot.iterrows():
448
  if sample[col] == 1:
449
  source = source_wells_32[i]
450
+ dest = get_well_position(int(sample['Sample']))
451
  vol = round(sample['volume donors (Β΅l)'], 2)
452
  robot_script_32.append({'Source': source, 'Destination': dest, 'Volume': vol})
453
 
 
455
  st.dataframe(robot_script_32_df)
456
  st.download_button("Download Robot Script (32-bit)", robot_script_32_df.to_csv(index=False), "robot_script_32bit.csv", key="download_robot_32")
457
 
 
458
  st.markdown("---")
459
 
460
  # ========== 31-BIT DECODING ==========
461
  st.subheader("31-bit Binary Grouped per Row")
462
+ st.write("Upload CSV with 31 columns (no headers), each row = one 6-bit ASCII character group or enter manually below.")
463
 
464
  binary31_file = st.file_uploader("Upload 31-bit Group CSV", type=["csv"], key="binary_31")
465
+
466
  if binary31_file:
467
  df_31 = pd.read_csv(binary31_file, header=None)
468
  df_31.columns = [str(h) for h in mutation_site_headers_actual] # assume ascending
469
+ else:
470
+ df_31 = st.data_editor(
471
+ pd.DataFrame(columns=[str(h) for h in mutation_site_headers_actual]),
472
+ num_rows="dynamic",
473
+ key="manual_31_input"
474
+ )
475
 
476
+ if not df_31.empty:
477
  reordered_df_31 = df_31[[str(h) for h in mutation_site_headers if str(h) in df_31.columns]]
478
  st.subheader("Binary Labels (Reordered 4402β†’3244, 4882β†’4455)")
479
  st.dataframe(reordered_df_31.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
480
  st.download_button("Download Reordered CSV", reordered_df_31.to_csv(index=False), "decoded_binary_31_reordered.csv", key="download_csv_tab5_31_reordered")
481
 
 
482
  decoded_flat_reordered = binary_labels_to_string(reordered_df_31.values.flatten().astype(int).tolist())
483
  st.subheader("Decoded String (Flattened 31-bit Reordered)")
484
  st.write(decoded_flat_reordered)
485
  st.download_button("Download Concatenated Output", decoded_flat_reordered, "decoded_31bit_string_reordered.txt", key="download_csv_tab5_31")
486
 
 
487
  df_31_asc = df_31[[str(h) for h in mutation_site_headers_actual if str(h) in df_31.columns]]
488
  st.subheader("Binary Labels (Ascending 3244β†’4882)")
489
  st.dataframe(df_31_asc.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
490
  st.download_button("Download Ascending CSV", df_31_asc.to_csv(index=False), "decoded_binary_31_ascending.csv", key="download_csv_tab5_31_ascend")
491
 
 
492
  decoded_flat_asc = binary_labels_to_string(df_31_asc.values.flatten().astype(int).tolist())
493
  st.subheader("Decoded String (Flattened 31-bit Ascending)")
494
  st.write(decoded_flat_asc)
495
  st.download_button("Download Concatenated Output", decoded_flat_asc, "decoded_31bit_string_ascending.txt", key="download_csv_tab5_31_asc")
496
+
497
  # === Robot Preparation Script from 31-bit Binary ===
498
  st.subheader("Robot Preparation Script from 31-bit Binary")
499
  robot_template_31 = pd.read_csv("/home/user/app/Robot2.csv", skiprows=3)