Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -542,7 +542,7 @@ with tab5:
|
|
| 542 |
st.header("Decode Binary Labels to String")
|
| 543 |
|
| 544 |
# Utility: Track source volumes and update if exceeds limit
|
| 545 |
-
def track_and_replace_source(source_list, robot_script, volume_limit):
|
| 546 |
source_volumes = {}
|
| 547 |
adjusted_sources = []
|
| 548 |
|
|
@@ -591,12 +591,28 @@ with tab5:
|
|
| 591 |
|
| 592 |
d_source_volumes[current_d_well] += fixed_volume
|
| 593 |
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 600 |
|
| 601 |
return d_source_script, d_source_volumes
|
| 602 |
|
|
@@ -609,19 +625,18 @@ with tab5:
|
|
| 609 |
wells.append(f"{row}{col}")
|
| 610 |
return wells
|
| 611 |
|
| 612 |
-
|
| 613 |
-
st.
|
| 614 |
-
st.write("Upload CSV with 32 columns (0 or 1), no headers, from EF Binary format or enter manually below.")
|
| 615 |
|
| 616 |
-
binary32_file = st.file_uploader("Upload
|
| 617 |
|
| 618 |
st.subheader("Optional Metadata (Optional)")
|
| 619 |
barcode_id_input = st.text_input("Barcode ID (applied to all rows, optional)", value="")
|
| 620 |
labware_source_input = st.text_input("Labware for Source (optional, default = 1)", value="1")
|
| 621 |
labware_dest_input = st.text_input("Labware for Destination (optional, default = 1)", value="1")
|
| 622 |
name_input = st.text_input("Name field (optional, default = blank)", value="")
|
| 623 |
-
volume_limit_input = st.number_input("Volume
|
| 624 |
-
|
| 625 |
if binary32_file:
|
| 626 |
df_32 = pd.read_csv(binary32_file, header=None)
|
| 627 |
df_32.columns = [str(h) for h in range(1, len(df_32.columns)+1)]
|
|
@@ -633,27 +648,16 @@ with tab5:
|
|
| 633 |
)
|
| 634 |
|
| 635 |
if not df_32.empty:
|
| 636 |
-
|
| 637 |
-
st.
|
| 638 |
-
st.
|
| 639 |
-
st.download_button("Download Reordered CSV", reordered_df_32.to_csv(index=False), "decoded_binary_32_reordered.csv", key="download_csv_tab5_32_reordered")
|
| 640 |
|
| 641 |
-
|
| 642 |
-
st.subheader("Decoded String
|
| 643 |
-
st.write(
|
| 644 |
-
st.download_button("Download Concatenated Output",
|
| 645 |
-
|
| 646 |
-
df_32_asc = df_32[[str(h) for h in mutation_site_headers_actual_3614 if str(h) in df_32.columns]]
|
| 647 |
-
st.subheader("Binary Labels (Ascending 3244→4882)")
|
| 648 |
-
st.dataframe(df_32_asc.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
|
| 649 |
-
st.download_button("Download Ascending CSV", df_32_asc.to_csv(index=False), "decoded_binary_32_ascending.csv", key="download_csv_tab5_32_ascend")
|
| 650 |
|
| 651 |
-
|
| 652 |
-
st.subheader("Decoded String (Flattened 32-bit Ascending)")
|
| 653 |
-
st.write(decoded_asc)
|
| 654 |
-
st.download_button("Download Concatenated Output", decoded_asc, "decoded_32bit_string_ascending.txt", key="download_txt_tab5_32_asc")
|
| 655 |
-
|
| 656 |
-
st.subheader("Robot Preparation Script from 32-bit Binary")
|
| 657 |
|
| 658 |
df_32_robot = df_32.copy()
|
| 659 |
df_32_robot.insert(0, 'Sample', range(1, len(df_32_robot)+1))
|
|
@@ -662,15 +666,14 @@ with tab5:
|
|
| 662 |
|
| 663 |
robot_script_32 = []
|
| 664 |
source_wells_32 = generate_source_wells(df_32.shape[1])
|
| 665 |
-
used_destinations = set()
|
| 666 |
|
| 667 |
for i, col in enumerate(df_32.columns):
|
| 668 |
for row_idx, sample in df_32_robot.iterrows():
|
| 669 |
if int(sample[col]) == 1:
|
| 670 |
source = source_wells_32[i]
|
| 671 |
dest = get_well_position(int(sample['Sample']))
|
| 672 |
-
used_destinations.add(dest)
|
| 673 |
vol = round(sample['volume donors (µl)'], 2)
|
|
|
|
| 674 |
if vol > 10:
|
| 675 |
half_vol = round(vol / 2, 2)
|
| 676 |
robot_script_32.append({
|
|
@@ -695,7 +698,7 @@ with tab5:
|
|
| 695 |
|
| 696 |
robot_script_32, source_volumes_32 = track_and_replace_source(source_wells_32, robot_script_32, volume_limit=volume_limit_input)
|
| 697 |
|
| 698 |
-
d_script, d_volumes = generate_fixed_d_source_instructions_to_all_samples(len(df_32_robot), volume_limit=volume_limit_input)
|
| 699 |
full_robot_script = robot_script_32 + d_script
|
| 700 |
|
| 701 |
robot_script_32_df = pd.DataFrame(full_robot_script)
|
|
@@ -706,10 +709,11 @@ with tab5:
|
|
| 706 |
robot_script_32_df = robot_script_32_df[['Barcode ID', 'Labware_Source', 'Source', 'Labware_Destination', 'Destination', 'Volume', 'Tool', 'Name']]
|
| 707 |
|
| 708 |
st.dataframe(robot_script_32_df)
|
| 709 |
-
st.download_button("Download Robot Script
|
| 710 |
|
| 711 |
st.subheader("Total Volume Used Per Source")
|
| 712 |
combined_volumes = {**source_volumes_32, **d_volumes}
|
| 713 |
source_volume_df = pd.DataFrame(list(combined_volumes.items()), columns=['Source', 'Total Volume (µl)'])
|
| 714 |
st.dataframe(source_volume_df)
|
| 715 |
-
st.download_button("Download Source Volumes", source_volume_df.to_csv(index=False), "source_total_volumes.csv", key="
|
|
|
|
|
|
| 542 |
st.header("Decode Binary Labels to String")
|
| 543 |
|
| 544 |
# Utility: Track source volumes and update if exceeds limit
|
| 545 |
+
def track_and_replace_source(source_list, robot_script, volume_limit=180):
|
| 546 |
source_volumes = {}
|
| 547 |
adjusted_sources = []
|
| 548 |
|
|
|
|
| 591 |
|
| 592 |
d_source_volumes[current_d_well] += fixed_volume
|
| 593 |
|
| 594 |
+
# Split if >10 and assign TS_10
|
| 595 |
+
if fixed_volume > 10:
|
| 596 |
+
half_vol = round(fixed_volume / 2, 2)
|
| 597 |
+
d_source_script.append({
|
| 598 |
+
'Source': current_d_well,
|
| 599 |
+
'Destination': dest,
|
| 600 |
+
'Volume': half_vol,
|
| 601 |
+
'Tool': 'TS_10'
|
| 602 |
+
})
|
| 603 |
+
d_source_script.append({
|
| 604 |
+
'Source': current_d_well,
|
| 605 |
+
'Destination': dest,
|
| 606 |
+
'Volume': fixed_volume - half_vol,
|
| 607 |
+
'Tool': 'TS_10'
|
| 608 |
+
})
|
| 609 |
+
else:
|
| 610 |
+
d_source_script.append({
|
| 611 |
+
'Source': current_d_well,
|
| 612 |
+
'Destination': dest,
|
| 613 |
+
'Volume': fixed_volume,
|
| 614 |
+
'Tool': 'TS_10'
|
| 615 |
+
})
|
| 616 |
|
| 617 |
return d_source_script, d_source_volumes
|
| 618 |
|
|
|
|
| 625 |
wells.append(f"{row}{col}")
|
| 626 |
return wells
|
| 627 |
|
| 628 |
+
st.subheader("Binary per Row")
|
| 629 |
+
st.write("Upload CSV with any number of columns (0 or 1), no headers, from EF Binary format or enter manually below.")
|
|
|
|
| 630 |
|
| 631 |
+
binary32_file = st.file_uploader("Upload Binary CSV", type=["csv"], key="binary_any")
|
| 632 |
|
| 633 |
st.subheader("Optional Metadata (Optional)")
|
| 634 |
barcode_id_input = st.text_input("Barcode ID (applied to all rows, optional)", value="")
|
| 635 |
labware_source_input = st.text_input("Labware for Source (optional, default = 1)", value="1")
|
| 636 |
labware_dest_input = st.text_input("Labware for Destination (optional, default = 1)", value="1")
|
| 637 |
name_input = st.text_input("Name field (optional, default = blank)", value="")
|
| 638 |
+
volume_limit_input = st.number_input("Maximum Volume Per Source Well (µl)", value=180)
|
| 639 |
+
|
| 640 |
if binary32_file:
|
| 641 |
df_32 = pd.read_csv(binary32_file, header=None)
|
| 642 |
df_32.columns = [str(h) for h in range(1, len(df_32.columns)+1)]
|
|
|
|
| 648 |
)
|
| 649 |
|
| 650 |
if not df_32.empty:
|
| 651 |
+
st.subheader("Binary Labels (Uploaded)")
|
| 652 |
+
st.dataframe(df_32.style.applymap(lambda v: "background-color: lightgreen" if v == 1 else "background-color: lightcoral"))
|
| 653 |
+
st.download_button("Download CSV", df_32.to_csv(index=False), "decoded_binary_uploaded.csv", key="download_csv_uploaded")
|
|
|
|
| 654 |
|
| 655 |
+
decoded = binary_labels_to_string(df_32.values.flatten().astype(int).tolist())
|
| 656 |
+
st.subheader("Decoded String")
|
| 657 |
+
st.write(decoded)
|
| 658 |
+
st.download_button("Download Concatenated Output", decoded, "decoded_binary_string.txt", key="download_txt_any")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 659 |
|
| 660 |
+
st.subheader("Robot Preparation Script from Binary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 661 |
|
| 662 |
df_32_robot = df_32.copy()
|
| 663 |
df_32_robot.insert(0, 'Sample', range(1, len(df_32_robot)+1))
|
|
|
|
| 666 |
|
| 667 |
robot_script_32 = []
|
| 668 |
source_wells_32 = generate_source_wells(df_32.shape[1])
|
|
|
|
| 669 |
|
| 670 |
for i, col in enumerate(df_32.columns):
|
| 671 |
for row_idx, sample in df_32_robot.iterrows():
|
| 672 |
if int(sample[col]) == 1:
|
| 673 |
source = source_wells_32[i]
|
| 674 |
dest = get_well_position(int(sample['Sample']))
|
|
|
|
| 675 |
vol = round(sample['volume donors (µl)'], 2)
|
| 676 |
+
|
| 677 |
if vol > 10:
|
| 678 |
half_vol = round(vol / 2, 2)
|
| 679 |
robot_script_32.append({
|
|
|
|
| 698 |
|
| 699 |
robot_script_32, source_volumes_32 = track_and_replace_source(source_wells_32, robot_script_32, volume_limit=volume_limit_input)
|
| 700 |
|
| 701 |
+
d_script, d_volumes = generate_fixed_d_source_instructions_to_all_samples(len(df_32_robot), fixed_volume=16, volume_limit=volume_limit_input)
|
| 702 |
full_robot_script = robot_script_32 + d_script
|
| 703 |
|
| 704 |
robot_script_32_df = pd.DataFrame(full_robot_script)
|
|
|
|
| 709 |
robot_script_32_df = robot_script_32_df[['Barcode ID', 'Labware_Source', 'Source', 'Labware_Destination', 'Destination', 'Volume', 'Tool', 'Name']]
|
| 710 |
|
| 711 |
st.dataframe(robot_script_32_df)
|
| 712 |
+
st.download_button("Download Robot Script", robot_script_32_df.to_csv(index=False), "robot_script.csv", key="download_robot_any")
|
| 713 |
|
| 714 |
st.subheader("Total Volume Used Per Source")
|
| 715 |
combined_volumes = {**source_volumes_32, **d_volumes}
|
| 716 |
source_volume_df = pd.DataFrame(list(combined_volumes.items()), columns=['Source', 'Total Volume (µl)'])
|
| 717 |
st.dataframe(source_volume_df)
|
| 718 |
+
st.download_button("Download Source Volumes", source_volume_df.to_csv(index=False), "source_total_volumes.csv", key="download_volume_any")
|
| 719 |
+
|