-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.justfile
More file actions
487 lines (416 loc) Β· 19.2 KB
/
project.justfile
File metadata and controls
487 lines (416 loc) Β· 19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
## Add your own just recipes here. This is imported by the main justfile.
# NOTE: The old single-mode analyze-experimental recipe has been replaced by a dual-mode version
# in the main justfile. The new version (defined in justfile, not project.justfile) supports both
# absolute and relative analysis modes. See main justfile for the updated recipe.
# DEPRECATED: Old single-mode experimental analysis (replaced by dual-mode version in main justfile)
# Analyze experimental plate data (statistical processing + visualization + clustering)
# [group('analysis')]
# analyze-experimental-legacy DATA_DIR="data/experimental/plate_designs_v10_maxprooptblock_long__results" OUTPUT_DIR="outputs/experimental_analysis":
# #!/usr/bin/env bash
# # set -euo pipefail
# ... (commented out - see git history for full recipe)
# Perform hierarchical clustering on replicate data
[group('analysis')]
cluster-replicates DATA_FILE="outputs/experimental_analysis/replicate_statistics.tsv" OUTPUT_DIR="outputs/clustering" FEATURE_TYPE="growth" N_CLUSTERS="6" SOURCE_DATA_ID="":
#!/usr/bin/env bash
set -euo pipefail
DATA_FILE="{{DATA_FILE}}"
OUTPUT_DIR="{{OUTPUT_DIR}}"
FEATURE_TYPE="{{FEATURE_TYPE}}"
N_CLUSTERS="{{N_CLUSTERS}}"
SOURCE_DATA_ID="{{SOURCE_DATA_ID}}"
echo "================================================================================"
echo "Hierarchical Clustering Analysis of Replicates"
echo "================================================================================"
echo ""
echo "π Data file: ${DATA_FILE}"
echo "π Output directory: ${OUTPUT_DIR}"
echo "π¬ Feature type: ${FEATURE_TYPE}"
echo "π Number of clusters: ${N_CLUSTERS}"
if [ -n "${SOURCE_DATA_ID}" ]; then
echo "π·οΈ Source data ID: ${SOURCE_DATA_ID}"
fi
echo ""
# Check if data file exists
if [ ! -f "${DATA_FILE}" ]; then
echo "β Error: Data file not found: ${DATA_FILE}"
echo ""
echo "Run 'just analyze-experimental' first to generate replicate statistics."
exit 1
fi
# Run clustering analysis (with optional source data ID)
if [ -n "${SOURCE_DATA_ID}" ]; then
uv run python scripts/cluster_heatmap_replicates.py "${DATA_FILE}" \
--output-dir "${OUTPUT_DIR}" \
--source-data-id "${SOURCE_DATA_ID}" \
--feature-type "${FEATURE_TYPE}" \
--n-clusters "${N_CLUSTERS}"
else
uv run python scripts/cluster_heatmap_replicates.py "${DATA_FILE}" \
--output-dir "${OUTPUT_DIR}" \
--feature-type "${FEATURE_TYPE}" \
--n-clusters "${N_CLUSTERS}"
fi
echo ""
echo "================================================================================"
echo "β
Clustering Complete!"
echo "================================================================================"
echo ""
echo "π Results saved to: ${OUTPUT_DIR}/"
echo ""
echo "Generated files:"
echo " - clustered_heatmap_${FEATURE_TYPE}.pdf (main visualization)"
echo " - clustered_heatmap_${FEATURE_TYPE}.png (for easy viewing)"
echo " - cluster_assignments_${FEATURE_TYPE}.csv (which cluster each replicate belongs to)"
echo " - cluster_summary_${FEATURE_TYPE}.pdf (cluster sizes and OD600 distributions)"
echo " - cluster_descriptions_${FEATURE_TYPE}.txt (detailed text summary)"
echo ""
echo "View heatmap:"
echo " open ${OUTPUT_DIR}/clustered_heatmap_${FEATURE_TYPE}.png"
echo ""
# Run complete clustering analysis (both growth and ingredient-based)
[group('analysis')]
cluster-all DATA_FILE="outputs/experimental_analysis/replicate_statistics.tsv" OUTPUT_DIR="outputs/clustering":
#!/usr/bin/env bash
set -euo pipefail
echo "================================================================================"
echo "Complete Clustering Analysis Pipeline"
echo "================================================================================"
echo ""
echo "Running both growth-based and ingredient-based clustering..."
echo ""
# Growth-based clustering
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "1. Growth-Based Clustering (OD600 trajectories)"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
just cluster-replicates "{{DATA_FILE}}" "{{OUTPUT_DIR}}" "growth" "6"
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "2. Ingredient-Based Clustering (media composition)"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
just cluster-replicates "{{DATA_FILE}}" "{{OUTPUT_DIR}}" "ingredients" "6"
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "3. Combined Clustering (growth + ingredients)"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
just cluster-replicates "{{DATA_FILE}}" "{{OUTPUT_DIR}}" "combined" "6"
echo ""
echo "================================================================================"
echo "β
All Clustering Complete!"
echo "================================================================================"
echo ""
echo "π All results in: {{OUTPUT_DIR}}/"
echo ""
echo "Key insights:"
echo " - Growth clusters show which conditions have similar performance"
echo " - Ingredient clusters show which media are similar in composition"
echo " - Combined clusters integrate both perspectives"
echo ""
echo "View summary:"
echo " cat {{OUTPUT_DIR}}/CLUSTERING_ANALYSIS_SUMMARY.md"
echo " open {{OUTPUT_DIR}}/clustered_heatmap_growth.png"
echo ""
# Generate a new LHS design version (creates all required output files)
[group('project management')]
generate-lhs-design VERSION SCRIPT_NAME:
#!/usr/bin/env bash
set -euo pipefail
VERSION_TAG="{{VERSION}}"
SCRIPT="scripts/{{SCRIPT_NAME}}"
DATE=$(date +"%Y-%m-%d %H:%M:%S")
echo "=== Generating LHS Design ${VERSION_TAG} ==="
echo ""
echo "π Using script: ${SCRIPT}"
echo "π Generated: ${DATE}"
echo ""
# Check if script exists
if [ ! -f "${SCRIPT}" ]; then
echo "β Error: Script not found: ${SCRIPT}"
echo ""
echo "Available LHS generation scripts:"
ls -1 scripts/generate_lhs*.py scripts/*lhs*.py 2>/dev/null || echo " No scripts found"
exit 1
fi
# Run the generation script
echo "π§ Running generation script..."
uv run python "${SCRIPT}"
# Check if output directory was created
OUTPUT_DIR="data/designs/MP_latinhypercube/plate_designs_${VERSION_TAG}"
if [ ! -d "${OUTPUT_DIR}" ]; then
echo "β Error: Output directory not created: ${OUTPUT_DIR}"
exit 1
fi
echo ""
echo "β
Design generation complete!"
echo ""
echo "π Verifying output files..."
FILE_COUNT=$(ls -1 "${OUTPUT_DIR}" | wc -l | tr -d ' ')
echo " Files created: ${FILE_COUNT}"
# Check for required files
echo ""
echo "π Checking standard output files..."
REQUIRED_FILES=(
"README_${VERSION_TAG}.md"
"DESIGN_CRITERIA_${VERSION_TAG}.md"
"CONCENTRATION_SUMMARY_${VERSION_TAG}.md"
"DELIVERY_SUMMARY_${VERSION_TAG}.md"
"pipetting_protocol_${VERSION_TAG}.csv"
"transfer_protocol_${VERSION_TAG}.csv"
"complete_formulations_${VERSION_TAG}.json"
"lhs_scatterplot_matrix_${VERSION_TAG}.png"
"lhs_scatterplot_matrix_${VERSION_TAG}.pdf"
)
MISSING_COUNT=0
for file in "${REQUIRED_FILES[@]}"; do
if [ -f "${OUTPUT_DIR}/${file}" ]; then
echo " β ${file}"
else
echo " β MISSING: ${file}"
MISSING_COUNT=$((MISSING_COUNT + 1))
fi
done
if [ $MISSING_COUNT -gt 0 ]; then
echo ""
echo "β οΈ Warning: ${MISSING_COUNT} required files missing!"
echo " Run completion script if needed:"
echo " uv run python scripts/complete_${VERSION_TAG}_outputs.py"
fi
echo ""
echo "π¦ Next steps:"
echo " 1. Review output files in: ${OUTPUT_DIR}"
echo " 2. Package design: just package-lhs-design ${VERSION_TAG}"
echo ""
# Create tarball of LHS design with proper naming (includes date stamp)
[group('project management')]
package-lhs-design VERSION:
#!/usr/bin/env bash
set -euo pipefail
# Variables
DESIGN_VERSION="{{VERSION}}"
DATE=$(date +"%Y%m%d")
TARBALL_NAME="MP_latinhypercube_${DESIGN_VERSION}_${DATE}.tar.gz"
DESIGN_DIR="data/designs/MP_latinhypercube"
echo "=== Packaging LHS Design ${DESIGN_VERSION} ==="
echo "π Date: ${DATE}"
echo ""
# Check if design directory exists
if [ ! -d "${DESIGN_DIR}/plate_designs_${DESIGN_VERSION}" ]; then
echo "β Error: Design directory not found: ${DESIGN_DIR}/plate_designs_${DESIGN_VERSION}"
echo ""
echo "Available designs:"
ls -1d ${DESIGN_DIR}/plate_designs_* 2>/dev/null || echo " No designs found"
exit 1
fi
# Navigate to design directory
cd "${DESIGN_DIR}"
# Create tarball directly (no temp directory needed)
echo "π¦ Creating tarball: ${TARBALL_NAME}"
tar -czf "${TARBALL_NAME}" \
plate_designs_${DESIGN_VERSION}/ \
MP_latinhypercube_list_ranges_${DESIGN_VERSION}.txt 2>/dev/null || \
tar -czf "${TARBALL_NAME}" \
plate_designs_${DESIGN_VERSION}/
# Calculate size
SIZE=$(du -h "${TARBALL_NAME}" | cut -f1)
FILE_COUNT=$(tar -tzf "${TARBALL_NAME}" | wc -l | tr -d ' ')
echo ""
echo "β
Package created successfully!"
echo ""
echo " File: ${TARBALL_NAME}"
echo " Size: ${SIZE}"
echo " Files: ${FILE_COUNT}"
echo " Location: ${DESIGN_DIR}/${TARBALL_NAME}"
echo ""
echo "π Contents:"
tar -tzf "${TARBALL_NAME}" | head -20
if [ ${FILE_COUNT} -gt 20 ]; then
echo " ... and $((FILE_COUNT - 20)) more files"
fi
echo ""
echo "To extract:"
echo " cd ${DESIGN_DIR}"
echo " tar -xzf ${TARBALL_NAME}"
echo ""
# Initialize provenance tracking tables in database
[group('database')]
init-provenance DB_PATH="data/processed/microgrow.duckdb":
uv run python scripts/migrate_provenance_schema.py {{DB_PATH}}
# Query provenance data from database
[group('database')]
query-provenance QUERY:
@echo "Querying provenance data..."
uv run python -c "import duckdb; conn = duckdb.connect('data/processed/microgrow.duckdb'); print(conn.execute('{{QUERY}}').fetchdf())"
# Show recent agent sessions
[group('database')]
show-sessions LIMIT="10":
@just query-provenance "SELECT session_id, agent_type, query, duration_ms, success FROM provenance_sessions ORDER BY created_at DESC LIMIT {{LIMIT}}"
# Show provenance statistics
[group('database')]
provenance-stats:
@echo "\n=== Provenance Statistics ==="
@just query-provenance "SELECT 'Total Sessions' as metric, COUNT(*) as count FROM provenance_sessions UNION ALL SELECT 'Total Events', COUNT(*) FROM provenance_events UNION ALL SELECT 'Total Tool Calls', COUNT(*) FROM provenance_tool_calls"
# ============== Research Auditor Recipes ==============
# Audit tool output (file validation, schema check)
[group('audit')]
audit-tool TOOL_NAME OUTPUT_PATH EXPECTED_COLUMNS="":
#!/usr/bin/env bash
set -euo pipefail
echo "================================================================================"
echo "Research Audit: Tool Output"
echo "================================================================================"
echo ""
echo "π Tool: {{TOOL_NAME}}"
echo "π Output: {{OUTPUT_PATH}}"
if [ -n "{{EXPECTED_COLUMNS}}" ]; then
echo "π Expected columns: {{EXPECTED_COLUMNS}}"
uv run python scripts/run_research_audit.py \
--scope tool \
--tool-name "{{TOOL_NAME}}" \
--output-path "{{OUTPUT_PATH}}" \
--expected-columns {{EXPECTED_COLUMNS}}
else
uv run python scripts/run_research_audit.py \
--scope tool \
--tool-name "{{TOOL_NAME}}" \
--output-path "{{OUTPUT_PATH}}"
fi
# Audit agent execution (output file check, provenance trace)
[group('audit')]
audit-agent SESSION_ID EXPECTED_OUTPUTS="" OUTPUT_DIR="":
#!/usr/bin/env bash
set -euo pipefail
echo "================================================================================"
echo "Research Audit: Agent Execution"
echo "================================================================================"
echo ""
echo "π€ Session: {{SESSION_ID}}"
if [ -n "{{EXPECTED_OUTPUTS}}" ] && [ -n "{{OUTPUT_DIR}}" ]; then
echo "π Expected outputs: {{EXPECTED_OUTPUTS}}"
echo "π Output directory: {{OUTPUT_DIR}}"
uv run python scripts/run_research_audit.py \
--scope agent \
--session-id "{{SESSION_ID}}" \
--expected-outputs {{EXPECTED_OUTPUTS}} \
--agent-output-dir "{{OUTPUT_DIR}}"
else
uv run python scripts/run_research_audit.py \
--scope agent \
--session-id "{{SESSION_ID}}"
fi
# Audit multi-agent workflow (checkpoint aggregation, hierarchy analysis)
[group('audit')]
audit-workflow WORKFLOW_ID ROOT_SESSION_ID:
#!/usr/bin/env bash
set -euo pipefail
echo "================================================================================"
echo "Research Audit: Workflow"
echo "================================================================================"
echo ""
echo "π Workflow: {{WORKFLOW_ID}}"
echo "π Root session: {{ROOT_SESSION_ID}}"
echo ""
uv run python scripts/run_research_audit.py \
--scope workflow \
--workflow-id "{{WORKFLOW_ID}}" \
--root-session-id "{{ROOT_SESSION_ID}}"
# Audit end-to-end pipeline (checksum verification, data integrity)
[group('audit')]
audit-pipeline PIPELINE_ID INPUT_DIR:
#!/usr/bin/env bash
set -euo pipefail
echo "================================================================================"
echo "Research Audit: Pipeline"
echo "================================================================================"
echo ""
echo "βοΈ Pipeline: {{PIPELINE_ID}}"
echo "π Input directory: {{INPUT_DIR}}"
echo ""
uv run python scripts/run_research_audit.py \
--scope pipeline \
--pipeline-id "{{PIPELINE_ID}}" \
--input-dir "{{INPUT_DIR}}"
# Example: Audit experimental analysis pipeline end-to-end
[group('audit')]
audit-experimental-pipeline SOURCE_DATA_ID:
#!/usr/bin/env bash
set -euo pipefail
INPUT_DIR="data/experimental/{{SOURCE_DATA_ID}}"
PIPELINE_ID="experimental-analysis-{{SOURCE_DATA_ID}}"
echo "================================================================================"
echo "Research Audit: Experimental Analysis Pipeline"
echo "================================================================================"
echo ""
echo "π Source data: {{SOURCE_DATA_ID}}"
echo "π Input directory: ${INPUT_DIR}"
echo ""
just audit-pipeline "${PIPELINE_ID}" "${INPUT_DIR}"
echo ""
echo "β
Pipeline audit complete"
echo "π View full report: .claude/audits/AUDIT_REPORT.md"
# ============================================================================
# AUDIT-ENABLED WORKFLOWS
# ============================================================================
# Generate MP_plus v10 with full audit trail (demonstration)
[group('audit')]
generate-mp-plus-v10-audited:
#!/usr/bin/env bash
set -euo pipefail
echo "================================================================================"
echo "MP_plus v10 Generation with ResearchAuditor - DEMONSTRATION"
echo "================================================================================"
echo ""
echo "This demonstrates audit integration in multi-agent workflows."
echo "Creates simplified MP_plus v10 recommendations with full audit trails."
echo ""
uv run python scripts/generate_mp_plus_v10_with_audit.py
echo ""
echo "β
Generation complete with audit trail"
echo "π Outputs:"
echo " - data/designs/MP_plus/MP_plus_v10_audited/"
echo " - data/designs/MP_plus/MP_plus_v10_audited/audits/{workflow_id}/"
echo "π Audit reports:"
echo " - audit_report.json (machine-readable)"
echo " - AUDIT_REPORT.md (human-readable)"
echo " - checkpoints/ (4 checkpoint files)"
# Run experimental analysis with ResearchAuditor monitoring
[group('audit')]
analyze-experimental-audited DATA_DIR OUTPUT_BASE="outputs":
#!/usr/bin/env bash
set -euo pipefail
DATA_DIR="{{DATA_DIR}}"
OUTPUT_BASE="{{OUTPUT_BASE}}"
echo "================================================================================"
echo "Experimental Analysis with ResearchAuditor"
echo "================================================================================"
echo ""
echo "π Data directory: ${DATA_DIR}"
echo "π Output base: ${OUTPUT_BASE}"
echo ""
uv run python scripts/run_dual_analysis_with_audit.py "${DATA_DIR}" \
--output-base "${OUTPUT_BASE}"
echo ""
echo "β
Analysis complete with audit checkpoints"
echo "π Audit reports:"
echo " - ${OUTPUT_BASE}/.claude/audits/{workflow_id}/audit_report.json"
echo " - ${OUTPUT_BASE}/.claude/audits/{workflow_id}/AUDIT_REPORT.md"
echo " - ${OUTPUT_BASE}/.claude/audits/{workflow_id}/checkpoints/"
# Run experimental analysis with audit (disable optional steps)
[group('audit')]
analyze-experimental-audited-minimal DATA_DIR OUTPUT_BASE="outputs":
#!/usr/bin/env bash
set -euo pipefail
DATA_DIR="{{DATA_DIR}}"
OUTPUT_BASE="{{OUTPUT_BASE}}"
echo "================================================================================"
echo "Experimental Analysis with ResearchAuditor (Minimal)"
echo "================================================================================"
echo ""
uv run python scripts/run_dual_analysis_with_audit.py "${DATA_DIR}" \
--output-base "${OUTPUT_BASE}" \
--disable-response-surfaces \
--disable-optimization-report
echo ""
echo "β
Minimal analysis complete with audit"