wenjun99 commited on
Commit
7215e2a
Β·
verified Β·
1 Parent(s): 7f5607e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -10
app.py CHANGED
@@ -391,6 +391,7 @@ with tab4:
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")
@@ -406,20 +407,28 @@ with tab5:
406
  else:
407
  # Reordered: 4402 β†’ 3244, 4882 β†’ 4455
408
  df_32.columns = [str(h) for h in mutation_site_headers_3614]
409
- all_bits = df_32.values.flatten().astype(int).tolist()
410
- decoded_reordered = binary_labels_to_string(all_bits)
411
 
 
 
 
 
 
 
 
 
 
412
  st.subheader("Decoded String (Reordered 4402β†’3244, 4882β†’4455)")
413
  st.write(decoded_reordered)
414
- st.download_button("Download Reordered CSV", df_32.to_csv(index=False), "decoded_binary_32_reordered.csv", key="download_csv_tab5_32_reordered")
415
 
416
  # Ascending: 3244 β†’ 4882
417
  df_ascending = df_32[[str(h) for h in mutation_site_headers_actual_3614 if str(h) in df_32.columns]]
418
- decoded_asc = binary_labels_to_string(df_ascending.values.flatten().astype(int).tolist())
 
 
419
 
 
420
  st.subheader("Decoded String (Ascending 3244β†’4882)")
421
  st.write(decoded_asc)
422
- st.download_button("Download Ascending CSV", df_ascending.to_csv(index=False), "decoded_binary_32_ascending.csv", key="download_csv_tab5_32_ascend")
423
 
424
  st.markdown("---")
425
 
@@ -430,18 +439,22 @@ with tab5:
430
  if binary31_file:
431
  df_31 = pd.read_csv(binary31_file, header=None)
432
 
433
- def trim_row(row):
434
- bits = row.dropna().astype(int).tolist()[:31]
435
- return bits
 
 
 
436
 
437
  decoded_rows = []
438
  for _, row in df_31.iterrows():
439
- bits = trim_row(row)
440
  decoded_rows.append(binary_labels_to_string(bits))
441
 
442
- st.subheader("Decoded String from 31-bit Chunks")
443
  full_decoded = "".join(decoded_rows)
 
444
  st.write(full_decoded)
445
 
446
  st.download_button("Download Concatenated Output", full_decoded, "decoded_31bit_string.txt", key="download_csv_tab5_31")
447
 
 
 
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")
 
407
  else:
408
  # Reordered: 4402 β†’ 3244, 4882 β†’ 4455
409
  df_32.columns = [str(h) for h in mutation_site_headers_3614]
 
 
410
 
411
+ # Show reordered binary
412
+ st.subheader("Binary Labels (Reordered 4402β†’3244, 4882β†’4455)")
413
+ reordered_df_32 = df_32[[str(h) for h in mutation_site_headers_3614 if str(h) in df_32.columns]]
414
+ st.dataframe(reordered_df_32.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
415
+ st.download_button("Download Reordered CSV", reordered_df_32.to_csv(index=False), "decoded_binary_32_reordered.csv", key="download_csv_tab5_32_reordered")
416
+
417
+ # Decode reordered binary to string
418
+ all_bits = reordered_df_32.values.flatten().astype(int).tolist()
419
+ decoded_reordered = binary_labels_to_string(all_bits)
420
  st.subheader("Decoded String (Reordered 4402β†’3244, 4882β†’4455)")
421
  st.write(decoded_reordered)
 
422
 
423
  # Ascending: 3244 β†’ 4882
424
  df_ascending = df_32[[str(h) for h in mutation_site_headers_actual_3614 if str(h) in df_32.columns]]
425
+ st.subheader("Binary Labels (Ascending 3244β†’4882)")
426
+ st.dataframe(df_ascending.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
427
+ st.download_button("Download Ascending CSV", df_ascending.to_csv(index=False), "decoded_binary_32_ascending.csv", key="download_csv_tab5_32_ascend")
428
 
429
+ decoded_asc = binary_labels_to_string(df_ascending.values.flatten().astype(int).tolist())
430
  st.subheader("Decoded String (Ascending 3244β†’4882)")
431
  st.write(decoded_asc)
 
432
 
433
  st.markdown("---")
434
 
 
439
  if binary31_file:
440
  df_31 = pd.read_csv(binary31_file, header=None)
441
 
442
+ # Reordered: 4402 β†’ 3244, 4882 β†’ 4455
443
+ df_31.columns = [str(h) for h in mutation_site_headers]
444
+
445
+ st.subheader("Binary Labels (Reordered 4402β†’3244, 4882β†’4455)")
446
+ st.dataframe(df_31.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
447
+ st.download_button("Download Reordered CSV", df_31.to_csv(index=False), "decoded_binary_31_reordered.csv", key="download_csv_tab5_31_reordered")
448
 
449
  decoded_rows = []
450
  for _, row in df_31.iterrows():
451
+ bits = row.dropna().astype(int).tolist()[:31]
452
  decoded_rows.append(binary_labels_to_string(bits))
453
 
 
454
  full_decoded = "".join(decoded_rows)
455
+ st.subheader("Decoded String from 31-bit Groups (Reordered 4402β†’3244, 4882β†’4455)")
456
  st.write(full_decoded)
457
 
458
  st.download_button("Download Concatenated Output", full_decoded, "decoded_31bit_string.txt", key="download_csv_tab5_31")
459
 
460
+