run_sheet¶
Sets SQR / SQRP and the i7/i5 barcodes of samples already in noxDB
from the sequencing run sheet (Overview_SQRs, tab All_SQRs, exported
as CSV). New samples get these values through the import instead.
The command wraps this module. It only reports unless given --commit:
# what would change, with a per-sample CSV to review
python scripts/apply_run_sheet.py "Overview_SQRs(All_SQRs).csv" --out changes.csv
# write it (one transaction; refused while stored values differ from the sheet)
python scripts/apply_run_sheet.py "Overview_SQRs(All_SQRs).csv" --commit
--project NAME limits it to one project's samples. --overwrite
replaces stored values that differ from the sheet instead of refusing.
run_sheet
¶
Read the sequencing run sheet and apply it to samples already in noxDB.
The run sheet is the All_SQRs tab of the lab's "Overview_SQRs"
workbook, exported as ;-separated CSV: a Barcodes banner row,
then the column names, then one row per sequenced well. It is the only
source of SQR/SQRP and of the i7/i5 barcodes. Columns are found
by name: SQR#, SQRP#, SampleName, i7 index,
i7 index ID, i5 index, i5 index ID.
The sheet and the database spell some samples differently, so matching takes two passes:
- Exact name. Covers most rows. A leading
Sample_on the sheet side is stripped first. - IP plate and well. The sheet has been seen to write a subject id
with hyphens where the database uses underscores, to carry a
different project label, and to append
_REPEAT. TheRxxPxx_<well>prefix survives all three.
A well sequenced in more than one run matches several rows. Only one
measurement per well ever reached the database, so the later run is
taken, as scripts/backfill_sequencing_coords.py did.
Applying goes through
samples.sequencing_changes: empty
columns are filled in, equal ones left alone, and a different stored
value is a conflict that is only replaced on request. The
scripts/apply_run_sheet.py command wraps all of this.
RunSheetRow
dataclass
¶
RunSheetRow(line: int, sample_name: str, sqr: str, sqrp: str, i7_index: str | None = None, i7_index_id: str | None = None, i5_index: str | None = None, i5_index_id: str | None = None)
One sequenced well of the run sheet.
sequencing
¶
The values this row sets, as keyword arguments for samples.
Source code in src/noxdb/run_sheet.py
Match
dataclass
¶
A sample in noxDB and the run-sheet row chosen for it.
Change
dataclass
¶
Change(sample_id: int, sample_name: str, changes: dict[str, Any], conflicts: list[str], error: str | None = None)
What applying a match would do to one sample.
sheet_name
¶
well_key
¶
IP plate and well of a sample name, or None if it carries neither.
Source code in src/noxdb/run_sheet.py
read_run_sheet
¶
Return every sequenced well in the run sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
The |
required |
encoding
|
str
|
File encoding. Undecodable bytes are replaced. |
'utf-8-sig'
|
Returns:
| Type | Description |
|---|---|
list[RunSheetRow]
|
One |
list[RunSheetRow]
|
sample name, in sheet order. |
list[RunSheetRow]
|
barcodes are stripped, and |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no header row has all the expected column names. |
Source code in src/noxdb/run_sheet.py
samples_to_match
¶
The samples a run sheet is matched against, with their sequencing columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cur
|
Cursor from |
required | |
project_name
|
str | None
|
Only this project's samples (including its linked
controls). |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
One dict per sample: |
list[dict[str, Any]]
|
|
Source code in src/noxdb/run_sheet.py
match_samples
¶
Pair each sample with the run-sheet row that describes it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
Iterable[RunSheetRow]
|
From |
required |
db_samples
|
Iterable[dict[str, Any]]
|
Dicts with at least |
required |
Returns:
| Type | Description |
|---|---|
MatchResult
|
A [ |
MatchResult
|
samples no row describes, and the rows no sample took. |
Source code in src/noxdb/run_sheet.py
plan_changes
¶
Work out what applying each match would change. Nothing is written.
Returns:
| Type | Description |
|---|---|
list[Change]
|
One |
list[Change]
|
change something or cannot be applied ( |
list[Change]
|
index sequence with characters other than A, C, G, T and N). |
Source code in src/noxdb/run_sheet.py
apply
¶
Write planned changes, all or nothing.
Rows that set the same columns are written together, so a whole run sheet is a handful of statements rather than one per sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cur
|
Audit-logging cursor from
|
required | |
changes
|
Iterable[Change]
|
From |
required |
overwrite
|
bool
|
Also replace values that differ from the stored ones. |
False
|
Returns:
| Type | Description |
|---|---|
int
|
The number of samples written. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Before writing anything, if a change has an error, or replaces a stored value and overwrite is not set. |