Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -393,7 +393,7 @@ with tab5:
|
|
| 393 |
st.header("Decode Binary Labels to String")
|
| 394 |
|
| 395 |
# Utility: Track source volumes and update if exceeds limit
|
| 396 |
-
def track_and_replace_source(source_list, robot_script, volume_limit=
|
| 397 |
source_volumes = {}
|
| 398 |
adjusted_sources = []
|
| 399 |
|
|
@@ -407,7 +407,6 @@ with tab5:
|
|
| 407 |
source_volumes[src] += vol
|
| 408 |
|
| 409 |
if source_volumes[src] > volume_limit:
|
| 410 |
-
# Convert A->E, B->F, ..., by shifting ASCII code +4
|
| 411 |
row_letter = src[0]
|
| 412 |
col_number = src[1:]
|
| 413 |
new_row_letter = chr(ord(row_letter) + 4)
|
|
@@ -434,7 +433,6 @@ with tab5:
|
|
| 434 |
for row_idx, sample in df_robot.iterrows():
|
| 435 |
for col in mutation_headers:
|
| 436 |
if col in sample and int(sample[col]) == 1:
|
| 437 |
-
# Check current D well volume
|
| 438 |
current_d_well = f"D{current_d_index}"
|
| 439 |
if current_d_well not in d_source_volumes:
|
| 440 |
d_source_volumes[current_d_well] = 0
|
|
@@ -458,13 +456,21 @@ with tab5:
|
|
| 458 |
|
| 459 |
return d_source_script, d_source_volumes
|
| 460 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
# ========== 32-BIT DECODING ==========
|
| 462 |
st.subheader("32-bit Binary per Row")
|
| 463 |
st.write("Upload CSV with 32 columns (0 or 1), no headers, from EF Binary format or enter manually below.")
|
| 464 |
|
| 465 |
binary32_file = st.file_uploader("Upload 32-bit Binary CSV", type=["csv"], key="binary_32")
|
| 466 |
|
| 467 |
-
# === Optional fields ===
|
| 468 |
st.subheader("Optional Metadata (Optional)")
|
| 469 |
barcode_id_input = st.text_input("Barcode ID (applied to all rows, optional)", value="")
|
| 470 |
labware_source_input = st.text_input("Labware for Source (optional, default = 1)", value="1")
|
|
@@ -502,10 +508,7 @@ with tab5:
|
|
| 502 |
st.write(decoded_asc)
|
| 503 |
st.download_button("Download Concatenated Output", decoded_asc, "decoded_32bit_string_ascending.txt", key="download_txt_tab5_32_asc")
|
| 504 |
|
| 505 |
-
# === Robot Preparation Script from 32-bit Binary ===
|
| 506 |
st.subheader("Robot Preparation Script from 32-bit Binary")
|
| 507 |
-
robot_template_32 = pd.read_csv("/home/user/app/Robot2.csv", skiprows=3)
|
| 508 |
-
robot_template_32.columns = ['Labware', 'Source', 'Labware_2', 'Destination', 'Volume', 'Tool', 'Name']
|
| 509 |
|
| 510 |
df_32_robot = df_32.copy()
|
| 511 |
df_32_robot.insert(0, 'Sample', range(1, len(df_32_robot)+1))
|
|
@@ -513,10 +516,7 @@ with tab5:
|
|
| 513 |
df_32_robot['volume donors (µl)'] = 64 / df_32_robot['# donors']
|
| 514 |
|
| 515 |
robot_script_32 = []
|
| 516 |
-
source_wells_32 =
|
| 517 |
-
if len(source_wells_32) < df_32.shape[1]:
|
| 518 |
-
source_wells_32 += [f"Fake{i}" for i in range(df_32.shape[1] - len(source_wells_32))]
|
| 519 |
-
source_wells_32 = source_wells_32[:df_32.shape[1]]
|
| 520 |
|
| 521 |
for i, col in enumerate(df_32.columns):
|
| 522 |
for row_idx, sample in df_32_robot.iterrows():
|
|
@@ -534,17 +534,15 @@ with tab5:
|
|
| 534 |
|
| 535 |
robot_script_32, source_volumes_32 = track_and_replace_source(source_wells_32, robot_script_32)
|
| 536 |
|
| 537 |
-
# Add fixed 16ul D sources
|
| 538 |
d_script, d_volumes = generate_fixed_d_source_instructions(df_32_robot)
|
| 539 |
full_robot_script = robot_script_32 + d_script
|
| 540 |
|
| 541 |
robot_script_32_df = pd.DataFrame(full_robot_script)
|
| 542 |
robot_script_32_df.insert(0, 'Barcode ID', barcode_id_input)
|
| 543 |
-
robot_script_32_df.insert(1, '
|
| 544 |
-
robot_script_32_df.insert(3, '
|
| 545 |
robot_script_32_df['Name'] = name_input
|
| 546 |
-
robot_script_32_df = robot_script_32_df[['Barcode ID', '
|
| 547 |
-
robot_script_32_df.columns = ['Barcode ID', 'Labware', 'Source', 'Labware', 'Destination', 'Volume', 'Tool', 'Name']
|
| 548 |
|
| 549 |
st.dataframe(robot_script_32_df)
|
| 550 |
st.download_button("Download Robot Script (32-bit)", robot_script_32_df.to_csv(index=False), "robot_script_32bit.csv", key="download_robot_32")
|
|
|
|
| 393 |
st.header("Decode Binary Labels to String")
|
| 394 |
|
| 395 |
# Utility: Track source volumes and update if exceeds limit
|
| 396 |
+
def track_and_replace_source(source_list, robot_script, volume_limit=180):
|
| 397 |
source_volumes = {}
|
| 398 |
adjusted_sources = []
|
| 399 |
|
|
|
|
| 407 |
source_volumes[src] += vol
|
| 408 |
|
| 409 |
if source_volumes[src] > volume_limit:
|
|
|
|
| 410 |
row_letter = src[0]
|
| 411 |
col_number = src[1:]
|
| 412 |
new_row_letter = chr(ord(row_letter) + 4)
|
|
|
|
| 433 |
for row_idx, sample in df_robot.iterrows():
|
| 434 |
for col in mutation_headers:
|
| 435 |
if col in sample and int(sample[col]) == 1:
|
|
|
|
| 436 |
current_d_well = f"D{current_d_index}"
|
| 437 |
if current_d_well not in d_source_volumes:
|
| 438 |
d_source_volumes[current_d_well] = 0
|
|
|
|
| 456 |
|
| 457 |
return d_source_script, d_source_volumes
|
| 458 |
|
| 459 |
+
def generate_source_wells(n):
|
| 460 |
+
wells = []
|
| 461 |
+
rows = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
| 462 |
+
for i in range(n):
|
| 463 |
+
row = rows[i // 12] # cycle through A, B, C...
|
| 464 |
+
col = (i % 12) + 1 # 1 to 12
|
| 465 |
+
wells.append(f"{row}{col}")
|
| 466 |
+
return wells
|
| 467 |
+
|
| 468 |
# ========== 32-BIT DECODING ==========
|
| 469 |
st.subheader("32-bit Binary per Row")
|
| 470 |
st.write("Upload CSV with 32 columns (0 or 1), no headers, from EF Binary format or enter manually below.")
|
| 471 |
|
| 472 |
binary32_file = st.file_uploader("Upload 32-bit Binary CSV", type=["csv"], key="binary_32")
|
| 473 |
|
|
|
|
| 474 |
st.subheader("Optional Metadata (Optional)")
|
| 475 |
barcode_id_input = st.text_input("Barcode ID (applied to all rows, optional)", value="")
|
| 476 |
labware_source_input = st.text_input("Labware for Source (optional, default = 1)", value="1")
|
|
|
|
| 508 |
st.write(decoded_asc)
|
| 509 |
st.download_button("Download Concatenated Output", decoded_asc, "decoded_32bit_string_ascending.txt", key="download_txt_tab5_32_asc")
|
| 510 |
|
|
|
|
| 511 |
st.subheader("Robot Preparation Script from 32-bit Binary")
|
|
|
|
|
|
|
| 512 |
|
| 513 |
df_32_robot = df_32.copy()
|
| 514 |
df_32_robot.insert(0, 'Sample', range(1, len(df_32_robot)+1))
|
|
|
|
| 516 |
df_32_robot['volume donors (µl)'] = 64 / df_32_robot['# donors']
|
| 517 |
|
| 518 |
robot_script_32 = []
|
| 519 |
+
source_wells_32 = generate_source_wells(df_32.shape[1])
|
|
|
|
|
|
|
|
|
|
| 520 |
|
| 521 |
for i, col in enumerate(df_32.columns):
|
| 522 |
for row_idx, sample in df_32_robot.iterrows():
|
|
|
|
| 534 |
|
| 535 |
robot_script_32, source_volumes_32 = track_and_replace_source(source_wells_32, robot_script_32)
|
| 536 |
|
|
|
|
| 537 |
d_script, d_volumes = generate_fixed_d_source_instructions(df_32_robot)
|
| 538 |
full_robot_script = robot_script_32 + d_script
|
| 539 |
|
| 540 |
robot_script_32_df = pd.DataFrame(full_robot_script)
|
| 541 |
robot_script_32_df.insert(0, 'Barcode ID', barcode_id_input)
|
| 542 |
+
robot_script_32_df.insert(1, 'Labware_Source', labware_source_input)
|
| 543 |
+
robot_script_32_df.insert(3, 'Labware_Destination', labware_dest_input)
|
| 544 |
robot_script_32_df['Name'] = name_input
|
| 545 |
+
robot_script_32_df = robot_script_32_df[['Barcode ID', 'Labware_Source', 'Source', 'Labware_Destination', 'Destination', 'Volume', 'Tool', 'Name']]
|
|
|
|
| 546 |
|
| 547 |
st.dataframe(robot_script_32_df)
|
| 548 |
st.download_button("Download Robot Script (32-bit)", robot_script_32_df.to_csv(index=False), "robot_script_32bit.csv", key="download_robot_32")
|