wenjun99 commited on
Commit
eaba82e
·
verified ·
1 Parent(s): 9347d7d

Updated app.py

Browse files

Tab5 now contains the full EpMotion script, with TS_10/TS_50, Source D wells, Name and barcode id columns

Files changed (1) hide show
  1. app.py +61 -7
app.py CHANGED
@@ -388,7 +388,6 @@ def get_well_position(sample_index):
388
  col_number = ((sample_index - 1) % 12) + 1
389
  return f"{row_letter}{col_number}"
390
 
391
- # Tab 5: Binary → String
392
  # Tab 5: Binary → String
393
  with tab5:
394
  st.header("Decode Binary Labels to String")
@@ -415,7 +414,6 @@ with tab5:
415
  new_src = f"{new_row_letter}{col_number}"
416
  entry['Source'] = new_src
417
 
418
- # Reset volume tracking for new source
419
  if new_src not in source_volumes:
420
  source_volumes[new_src] = 0
421
  source_volumes[new_src] += vol
@@ -425,12 +423,52 @@ with tab5:
425
 
426
  return adjusted_sources, source_volumes
427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
  # ========== 32-BIT DECODING ==========
429
  st.subheader("32-bit Binary per Row")
430
  st.write("Upload CSV with 32 columns (0 or 1), no headers, from EF Binary format or enter manually below.")
431
 
432
  binary32_file = st.file_uploader("Upload 32-bit Binary CSV", type=["csv"], key="binary_32")
433
 
 
 
 
 
 
 
 
434
  if binary32_file:
435
  df_32 = pd.read_csv(binary32_file, header=None)
436
  df_32.columns = [str(h) for h in mutation_site_headers_actual_3614]
@@ -484,18 +522,34 @@ with tab5:
484
  source = source_wells_32[i]
485
  dest = get_well_position(int(sample['Sample']))
486
  vol = round(sample['volume donors (µl)'], 2)
487
- robot_script_32.append({'Source': source, 'Destination': dest, 'Volume': vol})
 
 
 
 
 
 
488
 
489
- # Adjust for source well volume limit
490
  robot_script_32, source_volumes_32 = track_and_replace_source(source_wells_32, robot_script_32)
491
 
492
- robot_script_32_df = pd.DataFrame(robot_script_32)
 
 
 
 
 
 
 
 
 
 
 
493
  st.dataframe(robot_script_32_df)
494
  st.download_button("Download Robot Script (32-bit)", robot_script_32_df.to_csv(index=False), "robot_script_32bit.csv", key="download_robot_32")
495
 
496
- # Show total volume per source well
497
  st.subheader("Total Volume Used Per Source")
498
- source_volume_df = pd.DataFrame(list(source_volumes_32.items()), columns=['Source', 'Total Volume (µl)'])
 
499
  st.dataframe(source_volume_df)
500
  st.download_button("Download Source Volumes", source_volume_df.to_csv(index=False), "source_total_volumes.csv", key="download_volume_32")
501
 
 
388
  col_number = ((sample_index - 1) % 12) + 1
389
  return f"{row_letter}{col_number}"
390
 
 
391
  # Tab 5: Binary → String
392
  with tab5:
393
  st.header("Decode Binary Labels to String")
 
414
  new_src = f"{new_row_letter}{col_number}"
415
  entry['Source'] = new_src
416
 
 
417
  if new_src not in source_volumes:
418
  source_volumes[new_src] = 0
419
  source_volumes[new_src] += vol
 
423
 
424
  return adjusted_sources, source_volumes
425
 
426
+ # Utility: Track D source volume separately for fixed-volume dispensing
427
+ def generate_fixed_d_source_instructions(df_robot, fixed_volume=16, volume_limit=170):
428
+ d_source_volumes = {}
429
+ d_source_script = []
430
+ current_d_index = 1
431
+
432
+ for row_idx, sample in df_robot.iterrows():
433
+ for col in df_robot.columns[1:]:
434
+ if int(sample[col]) == 1:
435
+ # Check current D well volume
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
439
+
440
+ if d_source_volumes[current_d_well] + fixed_volume > volume_limit:
441
+ current_d_index += 1
442
+ current_d_well = f"D{current_d_index}"
443
+ d_source_volumes[current_d_well] = 0
444
+
445
+ d_source_volumes[current_d_well] += fixed_volume
446
+
447
+ dest = get_well_position(int(sample['Sample']))
448
+ tool = 'TS_10' if fixed_volume < 10 else 'TS_50'
449
+
450
+ d_source_script.append({
451
+ 'Source': current_d_well,
452
+ 'Destination': dest,
453
+ 'Volume': fixed_volume,
454
+ 'Tool': tool
455
+ })
456
+
457
+ return d_source_script, d_source_volumes
458
+
459
  # ========== 32-BIT DECODING ==========
460
  st.subheader("32-bit Binary per Row")
461
  st.write("Upload CSV with 32 columns (0 or 1), no headers, from EF Binary format or enter manually below.")
462
 
463
  binary32_file = st.file_uploader("Upload 32-bit Binary CSV", type=["csv"], key="binary_32")
464
 
465
+ # === Optional fields ===
466
+ st.subheader("Optional Metadata (Optional)")
467
+ barcode_id_input = st.text_input("Barcode ID (applied to all rows, optional)", value="")
468
+ labware_source_input = st.text_input("Labware for Source (optional, default = 1)", value="1")
469
+ labware_dest_input = st.text_input("Labware for Destination (optional, default = 1)", value="1")
470
+ name_input = st.text_input("Name field (optional, default = blank)", value="")
471
+
472
  if binary32_file:
473
  df_32 = pd.read_csv(binary32_file, header=None)
474
  df_32.columns = [str(h) for h in mutation_site_headers_actual_3614]
 
522
  source = source_wells_32[i]
523
  dest = get_well_position(int(sample['Sample']))
524
  vol = round(sample['volume donors (µl)'], 2)
525
+ tool = 'TS_10' if vol < 10 else 'TS_50'
526
+ robot_script_32.append({
527
+ 'Source': source,
528
+ 'Destination': dest,
529
+ 'Volume': vol,
530
+ 'Tool': tool
531
+ })
532
 
 
533
  robot_script_32, source_volumes_32 = track_and_replace_source(source_wells_32, robot_script_32)
534
 
535
+ # Add fixed 16ul D sources
536
+ d_script, d_volumes = generate_fixed_d_source_instructions(df_32_robot)
537
+ full_robot_script = robot_script_32 + d_script
538
+
539
+ robot_script_32_df = pd.DataFrame(full_robot_script)
540
+ robot_script_32_df.insert(0, 'Barcode ID', barcode_id_input)
541
+ robot_script_32_df.insert(1, 'Labware_1', labware_source_input)
542
+ robot_script_32_df.insert(3, 'Labware_2', labware_dest_input)
543
+ robot_script_32_df['Name'] = name_input
544
+ robot_script_32_df = robot_script_32_df[['Barcode ID', 'Labware_1', 'Source', 'Labware_2', 'Destination', 'Volume', 'Tool', 'Name']]
545
+ robot_script_32_df.columns = ['Barcode ID', 'Labware', 'Source', 'Labware', '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")
549
 
 
550
  st.subheader("Total Volume Used Per Source")
551
+ combined_volumes = {**source_volumes_32, **d_volumes}
552
+ source_volume_df = pd.DataFrame(list(combined_volumes.items()), columns=['Source', 'Total Volume (µl)'])
553
  st.dataframe(source_volume_df)
554
  st.download_button("Download Source Volumes", source_volume_df.to_csv(index=False), "source_total_volumes.csv", key="download_volume_32")
555