Command line#
dirconn-bids runs the dirconn pipeline on a BIDS dataset, following the BIDS App convention:
dirconn-bids BIDS_DIR OUTPUT_DIR participant [options]
It reads the region-level (or sensor-level) time series of every selected recording, prepares them,
estimates directed connectivity with the configured methods, tests it, runs the controls and writes a
derivatives dataset to OUTPUT_DIR/dirconn (see Outputs). What is computed is set by a TOML
file (see Pipeline configuration); the command line selects the inputs and the resources.
Only the participant level exists in dirconn 0.2.0; the group level arrives in dirconn 0.3.0 (until
then it stops with exit code 2 and the message “available in dirconn 0.3.0”). After every participant
run the command writes a report page sub-XX.html for each subject of the run and the methods
boilerplate logs/CITATION.* into the output dataset (see The participant report). --reports-only and
--boilerplate-only write them again from existing outputs without computing anything.
Install#
pip install "dirconn[app]"
The app extra adds pydantic, joblib and (on Python 3.10) tomli. Without it, dirconn-bids
--version, dirconn-bids --help and dirconn-bids list-methods still work; every other command
stops with exit code 2 and the hint pip install "dirconn[app]".
A first run#
dirconn-bids validate-config my_config.toml # prints OK <config hash>
dirconn-bids /data/bids /data/out participant \
--participant-label 01 02 --config my_config.toml --nprocs 4 -v
When it finishes, the command prints one line to stderr:
dirconn-bids: done 12, skipped 0, failed 0; run directory /data/out/dirconn/logs/run-20261117T094834-12184
Each recording (a unit, one sub/ses/task/run combination) gives one task per
method in estimation.methods plus one controls task (diagnostics and, when switched on, the
time-reversal control), so a run has units × (methods + 1) tasks. A failing method never takes the
controls or the other methods of its unit down with it.
Positional arguments#
BIDS_DIRRoot of the BIDS dataset. At
input.level = "roi"(the default) the inputs are read from the one directory belowBIDS_DIR/derivativeswhosedataset_description.jsonlistsGeneratedByName == "dirconn"(the region-level series of 0001 — BIDS layout for source-level ROI time series); connectivity outputs of dirconn and the output dataset of the run itself are skipped. Atinput.level = "sensor"the raw recordings ofBIDS_DIRare read, and anything belowBIDS_DIR/derivativesis skipped.OUTPUT_DIRThe results go to
OUTPUT_DIR/dirconn.OUTPUT_DIRmay not beBIDS_DIRitself nor lie inside it, except belowBIDS_DIR/derivatives:dirconn-bids /data/bids /data/bids/derivatives participantwrites/data/bids/derivatives/dirconnand can be run again on the same dataset.participant|groupThe analysis level;
groupis not available yet (exit code 2).
A BIDS directory whose name is a subcommand (validate-config or list-methods) must be written
with a path prefix, for example ./list-methods, or it is read as the subcommand.
Selecting the inputs#
--participant-label LABEL [LABEL ...]Subjects to process, with or without
sub-; default all.--session-id ID [ID ...]Sessions, with or without
ses-.--task-id ID [ID ...]Tasks, with or without
task-.--run-id ID [ID ...]Runs, with or without
run-.--bids-filter-file FILEA JSON object whose keys are among
subject,session,taskandrun, each holding a list of values (prefixes allowed):{"subject": ["01", "02"], "task": ["rest"]}
Unknown keys and values that are not lists are errors. The file is intersected with the other filters: a recording must pass both, so
--participant-label 01with a file listing subjects02and03selects nothing (and stops with exit code 2, “No recordings found”). Some BIDS Apps let the file replace the command-line filters; dirconn does not.
A recording with a session is skipped by --session-id filters that do not list it; one without a
session passes no --session-id filter. Several data files for one recording (split files) are an
error. Recordings are processed in the order (subject, session, task, run).
Configuration#
--config FILEThe TOML configuration; without it, the built-in default (see Pipeline configuration). Unknown keys are errors.
--set KEY=VALUEOverride one field by its dotted path, after the file is read; may be repeated, and the overrides are applied in order before the whole configuration is validated again. The value is split on the first
=:a field holding a list takes comma-separated values (
estimation.methods=gc,pdc,prepare.lock.events=go,stop); an empty value gives an empty list (estimation.exclude_freqs=). An existing band can be changed this way (estimation.bands.theta=4,7); a new band, orexclude_freqsranges, must be written in the TOML file;other fields take the text, converted and checked by the configuration model (
estimation.order=5,prepare.zscore=false,statistics.alpha=0.01);null(any case) turns a nullable field off (prepare.resample_hz=null,input.description=null);estimation.params.<method>.<key>=valuesets a keyword argument of an estimator and creates the table if needed; the value is read asnull,true/false, an integer, a float, or else kept as text (lists cannot be given this way). The method must be inestimation.methods.
A malformed override, an unknown path or a path that names a whole section stops the command with exit code 2 before anything runs; the first such override is reported. Invalid values are reported one line per problem with their dotted path.
Resources#
--work-dir DIRIntermediate files; default
OUTPUT_DIR/work. It holds the prepared-series cache (prepared-<hash>.npzwith a.jsonsidecar) shared by the tasks of a unit. The key of a cache entry covers the content of the unit’s files, thepreparesection,input.node_kinds, the dirconn version and the_events.tsvfile, so a stale entry is never reused; the directory can be deleted after a run.--nprocs NWorker processes (default 1). With more than one, tasks run in parallel processes (joblib, loky backend).
--omp-nthreads NThreads per worker for the numerical libraries (default 1). It sets
OMP_NUM_THREADS,OPENBLAS_NUM_THREADS,MKL_NUM_THREADSandNUMBA_NUM_THREADS, which the worker processes read when they start. The main process has already set up its BLAS thread pool (numpy is imported with dirconn), so with--nprocs 1the setting reaches only libraries that read the variables later; set the variables in the environment before startingdirconn-bidsto control that pool too. The number of threads can change floating-point sums in the last digits.--mem-mb NMemory limit in MB. It is recorded in
provenance.json; nothing enforces it.--resource-monitorNot implemented in dirconn 0.2.0: a warning is printed and the option is ignored.
Other options#
--skip-bids-validationDo not run
bids-validator. Otherwise it is run onBIDS_DIRwhen it is on thePATH(a warning is printed when it is not); a rejection stops the command with exit code 3.--reports-onlyRebuild the reports (
sub-XX.html, The participant report) and the methods boilerplate from the existing outputs ofOUTPUT_DIR/dirconn; nothing is recomputed. The subjects are the--participant-labelvalues (default: everysub-*directory of the dataset).BIDS_DIRis not read,bids-validatoris not run, and--config,--setand the input filters are ignored with a warning. Exit code 2 whenOUTPUT_DIR/dirconnhas nodirconn.tomlor a requested subject has no results.--boilerplate-onlyRewrite only the methods boilerplate (
logs/CITATION.*) from the existing outputs, under the same conditions. It excludes--reports-only.-v,--verboseMore log output on stderr:
-vinformation (one line per task),-vvdebug messages. The log filedirconn.logof the run always receives debug messages.--versionPrint
dirconn-bids <version>.-h,--helpPrint the options.
Subcommands#
dirconn-bids validate-config FILECheck a TOML configuration and print
OK <config hash>; errors go to stderr, one per line, and give exit code 2.dirconn-bids list-methodsList the methods that
estimation.methodsaccepts, one per line after a header, with the columnsname,report_kind,frequency_resolved,supports_maskandbackend.
Reports and the methods text#
After the tasks of a participant run have finished (exit code 0 or 1, not when the run stopped with
exit code 2), the command writes, for every subject that had a recording in the run,
OUTPUT_DIR/dirconn/sub-XX.html (The participant report explains what it shows), and then the methods text
of the whole output dataset, OUTPUT_DIR/dirconn/logs/CITATION.html, .md, .tex and .bib.
Each file is written to a temporary name and moved into place, so a reader never sees half a file. The
report of a subject covers all recordings of that subject in the output dataset, also those of earlier
runs. The command prints one line per report (dirconn-bids: report <path>) and one for the methods
text to stderr.
The reports are built from the files that are already in the dataset. They compute no connectivity,
and nothing a report does can change a result. When a report or the methods text cannot be written,
the command prints the reason and the name of the crash file, goes on with the other subjects and ends
with exit code 1; the traceback is in crash-report-<subject>.txt (or
crash-report-citation.txt) in the run directory.
--reports-only and --boilerplate-only do the same without a run:
They read
OUTPUT_DIR/dirconnonly.BIDS_DIRmust be given but is not read,bids-validatoris not run, and--config,--set,--session-id,--task-id,--run-idand--bids-filter-fileare ignored with a warning (also--participant-labelwith--boilerplate-only). Theappextra is needed for both.--reports-onlywrites the report of each subject in--participant-label(default: everysub-*directory of the dataset) and then the methods text;--boilerplate-onlywrites the methods text only. The methods text always covers every subject of the dataset.They exit with 2 when
OUTPUT_DIR/dirconnhas nodirconn.toml(it is not an output dataset ofdirconn-bids), when a requested subject has no results, when the dataset has no subject with--reports-only, and when both options are given. Failures leave crash files inlogs/reports-<UTC time>-<pid>/and give exit code 1.Nothing is computed and the result files are not touched; the figures are drawn again.
Use --reports-only after updating dirconn (a newer version may draw the report differently) or to
rebuild a report that failed.
Exit codes#
Code |
Meaning |
|---|---|
0 |
Every task succeeded or was already done. |
1 |
At least one task failed. The outputs of the other tasks are kept; each failure leaves a
|
2 |
The run did not start: invalid arguments, configuration or |
3 |
|
Running again and resuming#
A run can be repeated on the same OUTPUT_DIR, for example after an interruption, after adding
recordings or with other participants. Every task has a key computed from the content of the unit’s
input files, the analysis hash of the configuration (the prepare, estimation, statistics
and controls sections), the method (or controls) and the dirconn version. A task whose last
written file already carries its key (the TaskKey of the result sidecar; for the controls task the
desc-trgc sidecar, or the task_key of the diagnostics file when the time-reversal control is
off) is skipped and counted as skipped. Changed input files or a new dirconn version therefore
redo the affected tasks, and a task that failed or was interrupted is run again.
The first run writes the configuration to OUTPUT_DIR/dirconn/dirconn.toml. A later run is refused
(exit code 2, nothing written) when its analysis sections or its input section differ from that
file: results of different analyses never share a dataset. Use a new output directory, or run again
with the stored file (--config OUTPUT_DIR/dirconn/dirconn.toml). The output and execution
sections may change between runs; each run records its own effective configuration in its run
directory. They are not part of the task keys, so changing execution.seed or
output.long_table does not redo tasks that are already done.
Several jobs (for example one per participant on a cluster) may write to the same OUTPUT_DIR:
every run has its own run directory, the result files of different units do not overlap, and the
dataset files and cache entries are moved into place atomically. Start the first job alone, or wait
until OUTPUT_DIR/dirconn/dirconn.toml exists, before starting the others: two runs that start at
the same moment on an empty directory can both pass the configuration check.
Each job also rewrites logs/CITATION.* from the subjects that exist when it finishes, so the text
written by an early job does not cover the subjects of the later ones. Run
dirconn-bids BIDS_DIR OUTPUT_DIR participant --boilerplate-only once after the last job to get the
text for the whole dataset (--reports-only for the pages is not needed: each job writes the pages
of its own subjects).
Running in Docker#
The Docker image (see the README) has dirconn-bids as its entrypoint, so the arguments are those
above. Mount the BIDS dataset read-only at /data and an output directory at /out:
docker run --rm -v /path/to/bids:/data:ro -v /path/to/out:/out \
ghcr.io/hanweiliu-viola/dirconn:<tag> /data /out participant --participant-label 01
The report is then /path/to/out/dirconn/sub-01.html, and provenance.json of the run names the
image tag and revision (image). To rebuild the report from an existing output, give the same
mounts and add --reports-only. The image does not contain bids-validator: the command warns
that the dataset is not validated and goes on, so --skip-bids-validation is not needed. The
container runs as an unprivileged user (UID 1000); on Linux add --user $(id -u):$(id -g) when the
output directory belongs to someone else. Without arguments the image prints the help.
Where to look after a run#
OUTPUT_DIR/dirconn/logs/run-<UTC start time>-<pid>/ holds the log, the progress lines, the crash
files and the provenance of that run; Outputs describes every file. OUTPUT_DIR/dirconn/sub-XX.html is the report of
a subject (The participant report).