Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -394,17 +394,21 @@ with tab5:
|
|
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.")
|
398 |
-
binary32_file = st.file_uploader("Upload 32-bit Binary CSV", type=["csv"], key="binary_32")
|
399 |
-
|
400 |
|
|
|
401 |
|
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 |
-
|
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"))
|
@@ -414,7 +418,6 @@ with tab5:
|
|
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"))
|
@@ -431,7 +434,7 @@ with tab5:
|
|
431 |
|
432 |
df_32_robot = df_32.copy()
|
433 |
df_32_robot.insert(0, 'Sample', range(1, len(df_32_robot)+1))
|
434 |
-
df_32_robot['# donors'] = df_32_robot.iloc[:, 1:].sum(axis=1)
|
435 |
df_32_robot['volume donors (Β΅l)'] = 32 / df_32_robot['# donors']
|
436 |
|
437 |
robot_script_32 = []
|
@@ -442,9 +445,9 @@ with tab5:
|
|
442 |
|
443 |
for i, col in enumerate(df_32.columns):
|
444 |
for row_idx, sample in df_32_robot.iterrows():
|
445 |
-
if sample[col] == 1:
|
446 |
source = source_wells_32[i]
|
447 |
-
dest =
|
448 |
vol = round(sample['volume donors (Β΅l)'], 2)
|
449 |
robot_script_32.append({'Source': source, 'Destination': dest, 'Volume': vol})
|
450 |
|
@@ -452,12 +455,11 @@ with tab5:
|
|
452 |
st.dataframe(robot_script_32_df)
|
453 |
st.download_button("Download Robot Script (32-bit)", robot_script_32_df.to_csv(index=False), "robot_script_32bit.csv", key="download_robot_32")
|
454 |
|
455 |
-
|
456 |
st.markdown("---")
|
457 |
|
458 |
# ========== 31-BIT DECODING ==========
|
459 |
st.subheader("31-bit Binary Grouped per Row")
|
460 |
-
st.write("Upload CSV with 31 columns (no headers), each row = one 6-bit ASCII character group.")
|
461 |
|
462 |
binary31_file = st.file_uploader("Upload 31-bit Group CSV", type=["csv"], key="binary_31")
|
463 |
|
@@ -470,33 +472,28 @@ with tab5:
|
|
470 |
num_rows="dynamic",
|
471 |
key="manual_31_input"
|
472 |
)
|
473 |
-
|
474 |
-
if not df_31.empty:
|
475 |
|
476 |
-
|
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 |
-
# Flattened decoding for reordered
|
483 |
decoded_flat_reordered = binary_labels_to_string(reordered_df_31.values.flatten().astype(int).tolist())
|
484 |
st.subheader("Decoded String (Flattened 31-bit Reordered)")
|
485 |
st.write(decoded_flat_reordered)
|
486 |
st.download_button("Download Concatenated Output", decoded_flat_reordered, "decoded_31bit_string_reordered.txt", key="download_csv_tab5_31")
|
487 |
|
488 |
-
# Ascending: 3244 β 4882
|
489 |
df_31_asc = df_31[[str(h) for h in mutation_site_headers_actual if str(h) in df_31.columns]]
|
490 |
st.subheader("Binary Labels (Ascending 3244β4882)")
|
491 |
st.dataframe(df_31_asc.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
|
492 |
st.download_button("Download Ascending CSV", df_31_asc.to_csv(index=False), "decoded_binary_31_ascending.csv", key="download_csv_tab5_31_ascend")
|
493 |
|
494 |
-
# Flattened decoding for ascending
|
495 |
decoded_flat_asc = binary_labels_to_string(df_31_asc.values.flatten().astype(int).tolist())
|
496 |
st.subheader("Decoded String (Flattened 31-bit Ascending)")
|
497 |
st.write(decoded_flat_asc)
|
498 |
st.download_button("Download Concatenated Output", decoded_flat_asc, "decoded_31bit_string_ascending.txt", key="download_csv_tab5_31_asc")
|
499 |
-
|
500 |
# === Robot Preparation Script from 31-bit Binary ===
|
501 |
st.subheader("Robot Preparation Script from 31-bit Binary")
|
502 |
robot_template_31 = pd.read_csv("/home/user/app/Robot2.csv", skiprows=3)
|
@@ -504,7 +501,7 @@ with tab5:
|
|
504 |
|
505 |
df_31_robot = df_31.copy()
|
506 |
df_31_robot.insert(0, 'Sample', range(1, len(df_31_robot)+1))
|
507 |
-
df_31_robot['# donors'] = df_31_robot.iloc[:, 1:].sum(axis=1)
|
508 |
df_31_robot['volume donors (Β΅l)'] = 64 / df_31_robot['# donors']
|
509 |
|
510 |
robot_script_31 = []
|
@@ -515,7 +512,7 @@ with tab5:
|
|
515 |
|
516 |
for i, col in enumerate(df_31.columns):
|
517 |
for row_idx, sample in df_31_robot.iterrows():
|
518 |
-
if sample[col] == 1:
|
519 |
source = source_wells_31[i]
|
520 |
dest = get_well_position(int(sample['Sample']))
|
521 |
vol = round(sample['volume donors (Β΅l)'], 2)
|
@@ -523,4 +520,4 @@ with tab5:
|
|
523 |
|
524 |
robot_script_31_df = pd.DataFrame(robot_script_31)
|
525 |
st.dataframe(robot_script_31_df)
|
526 |
-
st.download_button("Download Robot Script (31-bit)", robot_script_31_df.to_csv(index=False), "robot_script_31bit.csv", key="download_robot_31")
|
|
|
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"))
|
|
|
434 |
|
435 |
df_32_robot = df_32.copy()
|
436 |
df_32_robot.insert(0, 'Sample', range(1, len(df_32_robot)+1))
|
437 |
+
df_32_robot['# donors'] = df_32_robot.iloc[:, 1:].astype(int).sum(axis=1)
|
438 |
df_32_robot['volume donors (Β΅l)'] = 32 / df_32_robot['# donors']
|
439 |
|
440 |
robot_script_32 = []
|
|
|
445 |
|
446 |
for i, col in enumerate(df_32.columns):
|
447 |
for row_idx, sample in df_32_robot.iterrows():
|
448 |
+
if int(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 |
|
|
|
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)
|
|
|
501 |
|
502 |
df_31_robot = df_31.copy()
|
503 |
df_31_robot.insert(0, 'Sample', range(1, len(df_31_robot)+1))
|
504 |
+
df_31_robot['# donors'] = df_31_robot.iloc[:, 1:].astype(int).sum(axis=1)
|
505 |
df_31_robot['volume donors (Β΅l)'] = 64 / df_31_robot['# donors']
|
506 |
|
507 |
robot_script_31 = []
|
|
|
512 |
|
513 |
for i, col in enumerate(df_31.columns):
|
514 |
for row_idx, sample in df_31_robot.iterrows():
|
515 |
+
if int(sample[col]) == 1:
|
516 |
source = source_wells_31[i]
|
517 |
dest = get_well_position(int(sample['Sample']))
|
518 |
vol = round(sample['volume donors (Β΅l)'], 2)
|
|
|
520 |
|
521 |
robot_script_31_df = pd.DataFrame(robot_script_31)
|
522 |
st.dataframe(robot_script_31_df)
|
523 |
+
st.download_button("Download Robot Script (31-bit)", robot_script_31_df.to_csv(index=False), "robot_script_31bit.csv", key="download_robot_31")
|