wenjun99 commited on
Commit
9e336e0
Β·
verified Β·
1 Parent(s): af02fd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -21
app.py CHANGED
@@ -342,32 +342,55 @@ with tab4:
342
 
343
  # Tab 5: Binary β†’ String
344
  with tab5:
345
- st.write("Upload a Binary Labels CSV (values 0 or 1 only):")
346
- st.write("**Note:** Please upload CSV files **without column headers**.")
347
- binary_file = st.file_uploader("Upload Binary CSV", type=["csv"], key="binary_csv")
348
 
349
- if binary_file:
350
- binary_df = pd.read_csv(binary_file, header=None)
 
351
 
352
- # Format for reordered (4402β†’3244, 4882β†’4455)
353
- binary_reordered = binary_df.iloc[:, :32].copy()
354
- binary_reordered.columns = [str(h) for h in mutation_site_headers_3614 if str(h) in binary_reordered.columns]
 
 
 
 
 
 
355
 
356
- all_bits_reordered = binary_reordered.values.flatten().astype(int).tolist()
357
- decoded_reordered = binary_labels_to_string(all_bits_reordered)
 
358
 
359
- st.subheader("Decoded String (Reordered 4402β†’3244, 4882β†’4455)")
360
- st.write(decoded_reordered)
361
- st.download_button("Download Reordered CSV", binary_reordered.to_csv(index=False), "binary_input_reordered.csv", key="download_csv_tab5_reordered")
362
 
363
- # Format for ascending (3244β†’4882)
364
- binary_ascending = binary_df.copy()
365
- binary_ascending.columns = [str(h) for h in mutation_site_headers_actual_3614 if str(h) in binary_ascending.columns]
366
 
367
- all_bits_ascending = binary_ascending.values.flatten().astype(int).tolist()
368
- decoded_ascending = binary_labels_to_string(all_bits_ascending)
369
 
370
- st.subheader("Decoded String (Ascending 3244β†’4882)")
371
- st.write(decoded_ascending)
372
- st.download_button("Download Ascending Order CSV", binary_ascending.to_csv(index=False), "binary_input_ascending.csv", key="download_csv_tab5_ascending")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
 
 
342
 
343
  # Tab 5: Binary β†’ String
344
  with tab5:
345
+ st.header("Decode Binary Labels to String")
 
 
346
 
347
+ st.subheader("πŸ”˜ Option 1: 32-bit Binary per Row")
348
+ st.write("Upload CSV with 32 columns (0 or 1), no headers, from EF Binary format.")
349
+ binary32_file = st.file_uploader("Upload 32-bit Binary CSV", type=["csv"], key="binary_32")
350
 
351
+ if binary32_file:
352
+ df_32 = pd.read_csv(binary32_file, header=None)
353
+ if df_32.shape[1] != 32:
354
+ st.warning("⚠️ CSV must have exactly 32 columns.")
355
+ else:
356
+ # Reordered: 4402 β†’ 3244, 4882 β†’ 4455
357
+ df_32.columns = [str(h) for h in mutation_site_headers_3614]
358
+ all_bits = df_32.values.flatten().astype(int).tolist()
359
+ decoded_reordered = binary_labels_to_string(all_bits)
360
 
361
+ st.subheader("Decoded String (Reordered 4402β†’3244, 4882β†’4455)")
362
+ st.write(decoded_reordered)
363
+ st.download_button("Download Reordered CSV", df_32.to_csv(index=False), "decoded_binary_32_reordered.csv", key="download_csv_tab5_32_reordered")
364
 
365
+ # Ascending: 3244 β†’ 4882
366
+ df_ascending = df_32[[str(h) for h in mutation_site_headers_actual_3614 if str(h) in df_32.columns]]
367
+ decoded_asc = binary_labels_to_string(df_ascending.values.flatten().astype(int).tolist())
368
 
369
+ st.subheader("Decoded String (Ascending 3244β†’4882)")
370
+ st.write(decoded_asc)
371
+ st.download_button("Download Ascending CSV", df_ascending.to_csv(index=False), "decoded_binary_32_ascending.csv", key="download_csv_tab5_32_ascend")
372
 
373
+ st.markdown("---")
 
374
 
375
+ st.subheader("πŸ”˜ Option 2: 31-bit Binary Grouped per Row")
376
+ st.write("Upload CSV with 31 columns per row (each row = one 6-bit ASCII chunk group).")
377
+ binary31_file = st.file_uploader("Upload 31-bit Group CSV", type=["csv"], key="binary_31")
378
+
379
+ if binary31_file:
380
+ df_31 = pd.read_csv(binary31_file, header=None)
381
+
382
+ def trim_row(row):
383
+ bits = row.dropna().astype(int).tolist()[:31]
384
+ return bits
385
+
386
+ decoded_rows = []
387
+ for _, row in df_31.iterrows():
388
+ bits = trim_row(row)
389
+ decoded_rows.append(binary_labels_to_string(bits))
390
+
391
+ st.subheader("Decoded String from 31-bit Chunks")
392
+ full_decoded = "".join(decoded_rows)
393
+ st.write(full_decoded)
394
+
395
+ st.download_button("Download Concatenated Output", full_decoded, "decoded_31bit_string.txt", key="download_csv_tab5_31")
396