Write the pooled-QC signal-correction program of a hospital metabolomics core (within-batch drift, restarts, partial QC injections, pool-lot bridging, specimen factors and feature acceptance on untargeted LC-HRMS feature tables) within a 60-minute session; it is run on further study exports from the same instrument with known abundances.
harbor run -t reactive-labs/lcms-drift-correctionharbor download reactive-labs/lcms-drift-correctionYou are Tobias Engvall, staff scientist in the Metabolomics and Bioanalysis Core (MBC) of Linnehavn University
Hospital. The core runs the KYNO-ICU sepsis study's specimens on its Kestrel 6500 Q-TOF in MS1 full scan, so besides
the targeted panel every injection holds the specimen's untargeted metabolome. KestrelQuant Discover picks and
aligns the features of a set of batches (a study) and exports them, but the correction step of SOP-MBC-040 has no
program yet. Today is Monday 23 November 2026. Sofie Brandt, the study's PI, wrote this morning (the mail is in
/app/inputs/docs/mail/):
Could you write it as one program that takes a study export folder and writes the corrected table: every feature, every specimen, the abundance relative to our reference pool, and a flag on the features we should not use. Lars wants to run it himself on the other study exports as part of the system check, so it has to run unattended and quickly on the processing PC. Please put the tables for the three exports on the share too.
You have 60 minutes. Whatever is in /app/output when the time is up is graded, so keep a working program saved
as you go.
In /app/inputs:
studies/: the three study exports on the share, KYNO-P01 (plasma, three batches), KYNO-C01 (CSF, one batch)
and KYNO-P02 (plasma, two long runs). Each folder holds the KestrelAcq sample list of every batch
(<batch>_sequence.xlsx, sheet Sequence) and the Discover tables <study>_features.csv (peak areas) and
<study>_heights.csv (apex heights): one row per feature (feature_id, mz, rt_min), one column per
injection named by its Data File; an empty cell means no peak was picked.docs/: SOP-MBC-040 rev 1 (the correction step), SOP-MBC-031 rev 4 and validation report VR-MBC-031-02 (the
targeted method the batches were acquired with), the instrument logbook, the stock preparation and pooled-QC
records, certificates of analysis, and mails./app/output/qc_correct.py, run as
python3 /app/output/qc_correct.py <study_dir> <out.csv>
It reads one study export folder in the format of the three in hand and writes one CSV file:
feature_id,flag,KI-0301-D1-P,KI-0302-D1-P,...
FT0001,0,1.084,0.7311,...
FT0002,1,0.95,,...
| Column | Content |
|---|---|
feature_id |
every feature of the export, as in <study>_features.csv |
flag |
1 if the feature cannot be corrected reliably with the pooled QC and must not be used, else 0 |
| one column per study specimen | every specimen of the study (sample type SMP), headed by its Sample ID, once (re-injections of a specimen get no column of their own) |
| values | the feature's abundance in the specimen as received (urine as voided) relative to the study's reference pool (1.0 = the same abundance as the pool); empty where the export has no peak for the specimen |
The program runs with Python 3.12, numpy, scipy, pandas and openpyxl, on one CPU core with 2 GB of memory and
no network, and must finish a study (up to 3 batches, 420 injections and 1100 features) within 8 seconds of
wall time. It is run as another user from a copy of /app/output: it may load helper files that you put in
/app/output (found relative to __file__), but /app/inputs is not there when it runs.
/app/output/results/<study>.csv for each of the three studies in hand (for example
/app/output/results/KYNO-P01.csv): the program's output for that study.
Lars runs your program on 24 further Discover exports of KYNO-ICU studies acquired on the same instrument between September and November 2026, from specimens whose metabolite abundances are known: plasma and CSF studies of one to three batches in the layouts SOP-MBC-031 allows. Some hold later study days of the subjects in the studies in hand. The three studies in hand have reference values too, and your result files are compared in the same way.
Abundances: a value is graded for every feature that is in truth correctable and every specimen whose first injection has a peak for it. With e = |ln(value / true value)|, it earns full credit for e up to τ = sqrt(0.06² + (1.5 s)²) and falls linearly to zero at 3τ, where s is the relative technical noise of that peak (ion counting, integration and injection variability; about 0.05 for strong peaks, more for weak peaks and in the salt front before 1 min). A missing, empty, non-positive or non-numeric value earns nothing. The study's abundance score is the mean credit, less the credit that writing 1.0 everywhere would earn, divided by the same quantity for the core's own reference program on that study (capped at 1).
Flags: your flagged features are compared with the features that in truth cannot be corrected reliably (not of specimen origin, not carried by the pool, outside the detector's linear range, or too imprecise in the pooled QC to be corrected; internal standards and merged signals are left out) by the Jaccard index, divided by the reference program's index (capped at 1). The flag score counts in full only when the abundance score is at least 0.5, and in proportion below that.
A study scores 0.7 × abundance score + 0.3 × flag score. A study on which the program fails, runs out of time or writes no readable CSV scores zero. The final score is 80 % the mean over the 24 further studies and 20 % the mean over the three result files.