wenjun99 commited on
Commit
7f5607e
·
verified ·
1 Parent(s): aea317a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -20
app.py CHANGED
@@ -145,35 +145,47 @@ with tab1:
145
  st.dataframe(robot_script_df)
146
  st.download_button("Download Robot Script CSV", robot_script_df.to_csv(index=False), "robot_script.csv", key="download_csv_tab1_robot")
147
 
148
- # === Robot Preparation Script (Based on Ascending Order 3244 → 4882) ===
149
- st.subheader("Robot Preparation Script (Based on Ascending Order 3244 → 4882)")
150
 
151
- df_sorted_ascend =df[[str(h) for h in ascending_headers if str(h) in df.columns]].copy()
 
 
 
 
 
 
152
 
153
- # Only insert 'Sample' if it doesn't already exist
154
- if 'Sample' not in df_sorted_ascend.columns:
155
- df_sorted_ascend.insert(0, 'Sample', range(1, len(df_sorted_ascend)+1))
156
 
157
- # Recalculate donors and volume
158
- df_sorted_ascend['# donors'] = df_sorted_ascend.iloc[:, 1:].sum(axis=1)
159
- df_sorted_ascend['volume donors (µl)'] = 32 / df_sorted_ascend['# donors']
160
-
161
- st.subheader("df_sorted_ascend")
162
- st.write(df_sorted_ascend)
 
 
 
 
 
 
 
163
 
164
- robot_script_ascend = []
165
- # Use the same 32 source wells
166
- for i, col in enumerate(df_sorted_ascend.columns[1:33]):
167
- for row_idx, sample in df_sorted_ascend.iterrows():
168
  if sample[col] == 1:
169
  source = source_wells[i]
170
  dest = f"A{sample['Sample']}"
171
  vol = round(sample['volume donors (µl)'], 2)
172
- robot_script_ascend.append({'Source': source, 'Destination': dest, 'Volume': vol})
173
 
174
- robot_script_ascend_df = pd.DataFrame(robot_script_ascend)
175
- st.dataframe(robot_script_ascend_df)
176
- st.download_button("Download Ascending Robot Script CSV", robot_script_ascend_df.to_csv(index=False), "robot_script_ascending.csv", key="download_csv_tab1_robot_ascend")
177
 
178
  # Tab 2: EF → Binary
179
  with tab2:
 
145
  st.dataframe(robot_script_df)
146
  st.download_button("Download Robot Script CSV", robot_script_df.to_csv(index=False), "robot_script.csv", key="download_csv_tab1_robot")
147
 
148
+ # === Robot Preparation Script (Custom Order: 4402 3244, 4882 4455) ===
149
+ st.subheader("Robot Preparation Script (Custom Order: 4402 3244, 4882 4455)")
150
 
151
+ # Include 3614 in custom header list
152
+ custom_headers = [
153
+ 4402, 4349, 4298, 4245, 4190, 4145, 4089, 4039,
154
+ 3985, 3933, 3879, 3824, 3773, 3720, 3665, 3614,
155
+ 3562, 3509, 3455, 3399, 3350, 3297, 3244,
156
+ 4882, 4828, 4773, 4720, 4668, 4615, 4561, 4510, 4455
157
+ ]
158
 
159
+ # Create a copy of df and reorder columns based on custom headers
160
+ df_sorted_custom = df[[str(h) for h in custom_headers if str(h) in df.columns]].copy()
 
161
 
162
+ # Insert fake column "3614" if missing
163
+ if "3614" not in df_sorted_custom.columns:
164
+ idx = custom_headers.index(3614)
165
+ insert_at = idx # 0-based index
166
+ df_sorted_custom.insert(insert_at, "3614", 0)
167
+
168
+ # Insert 'Sample' if missing
169
+ if "Sample" not in df_sorted_custom.columns:
170
+ df_sorted_custom.insert(0, 'Sample', range(1, len(df_sorted_custom) + 1))
171
+
172
+ # Calculate donor info
173
+ df_sorted_custom['# donors'] = df_sorted_custom.iloc[:, 1:].sum(axis=1)
174
+ df_sorted_custom['volume donors (µl)'] = 32 / df_sorted_custom['# donors']
175
 
176
+ # Generate robot script
177
+ robot_script_custom = []
178
+ for i, col in enumerate(df_sorted_custom.columns[1:33]): # 32 columns after Sample
179
+ for row_idx, sample in df_sorted_custom.iterrows():
180
  if sample[col] == 1:
181
  source = source_wells[i]
182
  dest = f"A{sample['Sample']}"
183
  vol = round(sample['volume donors (µl)'], 2)
184
+ robot_script_custom.append({'Source': source, 'Destination': dest, 'Volume': vol})
185
 
186
+ robot_script_custom_df = pd.DataFrame(robot_script_custom)
187
+ st.dataframe(robot_script_custom_df)
188
+ st.download_button("Download Custom Order Robot Script CSV", robot_script_custom_df.to_csv(index=False), "robot_script_custom_order.csv", key="download_csv_tab1_robot_custom")
189
 
190
  # Tab 2: EF → Binary
191
  with tab2: