wenjun99 commited on
Commit
a047ed7
Β·
verified Β·
1 Parent(s): 9680a50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -54
app.py CHANGED
@@ -391,81 +391,77 @@ with tab4:
391
  st.subheader("Decoded String (continuous across rows)")
392
  st.write(decoded_string)
393
 
394
- # Tab 5: Binary β†’ String
395
  # Tab 5: Binary β†’ String
396
  with tab5:
397
  st.header("Decode Binary Labels to String")
398
 
 
399
  st.subheader("πŸ”˜ Option 1: 32-bit Binary per Row")
400
  st.write("Upload CSV with 32 columns (0 or 1), no headers, from EF Binary format.")
401
  binary32_file = st.file_uploader("Upload 32-bit Binary CSV", type=["csv"], key="binary_32")
402
 
403
  if binary32_file:
404
  df_32 = pd.read_csv(binary32_file, header=None)
405
-
406
- # Apply known ascending order headers manually:
407
- df_32.columns = [str(h) for h in mutation_site_headers_actual_3614]
408
-
409
- # Reorder for 4402β†’3244 + 4882β†’4455 visualization:
410
- df_32 = df_32[[str(h) for h in mutation_site_headers_3614]]
411
-
412
- if df_32.shape[1] != 32:
413
- st.warning("⚠️ CSV must have exactly 32 columns.")
414
- else:
415
- # Reordered: 4402 β†’ 3244, 4882 β†’ 4455
416
- df_32.columns = [str(h) for h in mutation_site_headers_3614]
417
-
418
- # Show reordered binary
419
- st.subheader("Binary Labels (Reordered 4402β†’3244, 4882β†’4455)")
420
- reordered_df_32 = df_32[[str(h) for h in mutation_site_headers_3614 if str(h) in df_32.columns]]
421
- st.dataframe(reordered_df_32.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
422
- st.download_button("Download Reordered CSV", reordered_df_32.to_csv(index=False), "decoded_binary_32_reordered.csv", key="download_csv_tab5_32_reordered")
423
-
424
- # Decode reordered binary to string
425
- all_bits = reordered_df_32.values.flatten().astype(int).tolist()
426
- decoded_reordered = binary_labels_to_string(all_bits)
427
- st.subheader("Decoded String (Reordered 4402β†’3244, 4882β†’4455)")
428
- st.write(decoded_reordered)
429
-
430
- # Ascending: 3244 β†’ 4882
431
- df_ascending = df_32[[str(h) for h in mutation_site_headers_actual_3614 if str(h) in df_32.columns]]
432
- st.subheader("Binary Labels (Ascending 3244β†’4882)")
433
- st.dataframe(df_ascending.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
434
- st.download_button("Download Ascending CSV", df_ascending.to_csv(index=False), "decoded_binary_32_ascending.csv", key="download_csv_tab5_32_ascend")
435
-
436
- decoded_asc = binary_labels_to_string(df_ascending.values.flatten().astype(int).tolist())
437
- st.subheader("Decoded String (Ascending 3244β†’4882)")
438
- st.write(decoded_asc)
439
 
440
  st.markdown("---")
441
 
 
442
  st.subheader("πŸ”˜ Option 2: 31-bit Binary Grouped per Row")
443
- st.write("Upload CSV with 31 columns per row (each row = one 6-bit ASCII chunk group).")
444
- binary31_file = st.file_uploader("Upload 31-bit Group CSV", type=["csv"], key="binary_31")
445
 
 
446
  if binary31_file:
447
  df_31 = pd.read_csv(binary31_file, header=None)
448
- # Assume known ascending order and assign:
449
- df_31.columns = [str(h) for h in mutation_site_headers_actual]
450
-
451
- # Reorder:
452
- df_31 = df_31[[str(h) for h in mutation_site_headers]]
453
- # Reordered: 4402 β†’ 3244, 4882 β†’ 4455
454
- df_31.columns = [str(h) for h in mutation_site_headers]
455
 
 
 
456
  st.subheader("Binary Labels (Reordered 4402β†’3244, 4882β†’4455)")
457
- st.dataframe(df_31.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
458
- st.download_button("Download Reordered CSV", df_31.to_csv(index=False), "decoded_binary_31_reordered.csv", key="download_csv_tab5_31_reordered")
459
-
460
- decoded_rows = []
461
- for _, row in df_31.iterrows():
462
- bits = row.dropna().astype(int).tolist()[:31]
463
- decoded_rows.append(binary_labels_to_string(bits))
464
 
465
- full_decoded = "".join(decoded_rows)
 
 
 
 
466
  st.subheader("Decoded String from 31-bit Groups (Reordered 4402β†’3244, 4882β†’4455)")
467
- st.write(full_decoded)
 
468
 
469
- st.download_button("Download Concatenated Output", full_decoded, "decoded_31bit_string.txt", key="download_csv_tab5_31")
 
 
 
 
470
 
 
 
 
 
 
 
 
 
471
 
 
391
  st.subheader("Decoded String (continuous across rows)")
392
  st.write(decoded_string)
393
 
 
394
  # Tab 5: Binary β†’ String
395
  with tab5:
396
  st.header("Decode Binary Labels to String")
397
 
398
+ # ========== 32-BIT DECODING ==========
399
  st.subheader("πŸ”˜ Option 1: 32-bit Binary per Row")
400
  st.write("Upload CSV with 32 columns (0 or 1), no headers, from EF Binary format.")
401
  binary32_file = st.file_uploader("Upload 32-bit Binary CSV", type=["csv"], key="binary_32")
402
 
403
  if binary32_file:
404
  df_32 = pd.read_csv(binary32_file, header=None)
405
+ df_32.columns = [str(h) for h in mutation_site_headers_actual_3614] # assume ascending
406
+
407
+ # Reordered: 4402 β†’ 3244, 4882 β†’ 4455
408
+ reordered_df_32 = df_32[[str(h) for h in mutation_site_headers_3614 if str(h) in df_32.columns]]
409
+ st.subheader("Binary Labels (Reordered 4402β†’3244, 4882β†’4455)")
410
+ st.dataframe(reordered_df_32.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
411
+ st.download_button("Download Reordered CSV", reordered_df_32.to_csv(index=False), "decoded_binary_32_reordered.csv", key="download_csv_tab5_32_reordered")
412
+
413
+ decoded_reordered = binary_labels_to_string(reordered_df_32.values.flatten().astype(int).tolist())
414
+ st.subheader("Decoded String (Reordered 4402β†’3244, 4882β†’4455)")
415
+ st.write(decoded_reordered)
416
+
417
+ # Ascending: 3244 β†’ 4882
418
+ df_ascending = df_32[[str(h) for h in mutation_site_headers_actual_3614 if str(h) in df_32.columns]]
419
+ st.subheader("Binary Labels (Ascending 3244β†’4882)")
420
+ st.dataframe(df_ascending.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
421
+ st.download_button("Download Ascending CSV", df_ascending.to_csv(index=False), "decoded_binary_32_ascending.csv", key="download_csv_tab5_32_ascend")
422
+
423
+ decoded_asc = binary_labels_to_string(df_ascending.values.flatten().astype(int).tolist())
424
+ st.subheader("Decoded String (Ascending 3244β†’4882)")
425
+ st.write(decoded_asc)
 
 
 
 
 
 
 
 
 
 
 
 
 
426
 
427
  st.markdown("---")
428
 
429
+ # ========== 31-BIT DECODING ==========
430
  st.subheader("πŸ”˜ Option 2: 31-bit Binary Grouped per Row")
431
+ st.write("Upload CSV with 31 columns (no headers), each row = one 6-bit ASCII character group.")
 
432
 
433
+ binary31_file = st.file_uploader("Upload 31-bit Group CSV", type=["csv"], key="binary_31")
434
  if binary31_file:
435
  df_31 = pd.read_csv(binary31_file, header=None)
436
+ df_31.columns = [str(h) for h in mutation_site_headers_actual] # assume ascending
 
 
 
 
 
 
437
 
438
+ # Reordered: 4402 β†’ 3244, 4882 β†’ 4455
439
+ reordered_df_31 = df_31[[str(h) for h in mutation_site_headers if str(h) in df_31.columns]]
440
  st.subheader("Binary Labels (Reordered 4402β†’3244, 4882β†’4455)")
441
+ st.dataframe(reordered_df_31.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
442
+ st.download_button("Download Reordered CSV", reordered_df_31.to_csv(index=False), "decoded_binary_31_reordered.csv", key="download_csv_tab5_31_reordered")
 
 
 
 
 
443
 
444
+ decoded_rows_reordered = [
445
+ binary_labels_to_string(row.dropna().astype(int).tolist()[:31])
446
+ for _, row in reordered_df_31.iterrows()
447
+ ]
448
+ full_decoded_reordered = "".join(decoded_rows_reordered)
449
  st.subheader("Decoded String from 31-bit Groups (Reordered 4402β†’3244, 4882β†’4455)")
450
+ st.write(full_decoded_reordered)
451
+ st.download_button("Download Concatenated Output", full_decoded_reordered, "decoded_31bit_string_reordered.txt", key="download_csv_tab5_31")
452
 
453
+ # Ascending: 3244 β†’ 4882
454
+ df_31_asc = df_31[[str(h) for h in mutation_site_headers_actual if str(h) in df_31.columns]]
455
+ st.subheader("Binary Labels (Ascending 3244β†’4882)")
456
+ st.dataframe(df_31_asc.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
457
+ st.download_button("Download Ascending CSV", df_31_asc.to_csv(index=False), "decoded_binary_31_ascending.csv", key="download_csv_tab5_31_ascend")
458
 
459
+ decoded_rows_asc = [
460
+ binary_labels_to_string(row.dropna().astype(int).tolist()[:31])
461
+ for _, row in df_31_asc.iterrows()
462
+ ]
463
+ full_decoded_asc = "".join(decoded_rows_asc)
464
+ st.subheader("Decoded String from 31-bit Groups (Ascending 3244β†’4882)")
465
+ st.write(full_decoded_asc)
466
+ st.download_button("Download Concatenated Output", full_decoded_asc, "decoded_31bit_string_ascending.txt", key="download_csv_tab5_31_asc")
467