-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft pre-init ingression #102
Changes from 17 commits
eb86d69
21702d1
fb6bacf
bca8832
60e4cea
747579a
742ff2b
02e2dfe
a316f94
61d4f07
4467831
08478ea
b6305b9
897a780
0df2933
297c1eb
04491af
6e096ca
69f3fd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,11 +23,12 @@ dependencies = [ | |
"filelock", | ||
"fury", | ||
"indexed_gzip <= 1.8.7", | ||
"Ingress2QSIRecon == 0.2.1", | ||
"jinja2 < 3.1", | ||
"matplotlib", | ||
"networkx ~= 2.8.8", | ||
"nibabel <= 5.2.0", | ||
"nilearn == 0.10.1", | ||
"nibabel <= 6.0.0", | ||
"nilearn", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a need to unpin this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah this was a holdout from some dependency differences between qsirecon and i2q, we should be able to pin it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in last commit |
||
"nipype == 1.8.6", | ||
"nireports ~= 24.0.2", | ||
"niworkflows >=1.9,<= 1.10", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,11 +116,16 @@ def _bids_filter(value, parser): | |
# required, positional arguments | ||
# IMPORTANT: they must go directly with the parser object | ||
parser.add_argument( | ||
"bids_dir", | ||
"input_dir", | ||
action="store", | ||
metavar="input_dir", | ||
type=PathExists, | ||
help="The root folder of a BIDS valid dataset (sub-XXXXX folders should " | ||
"be found at the top level in this folder).", | ||
help=( | ||
"The root folder of the input dataset " | ||
"(subject-level folders should be found at the top level in this folder). " | ||
"If the dataset is not BIDS-valid, " | ||
"then a BIDS-compliant version will be created based on the --input-type value." | ||
), | ||
) | ||
parser.add_argument( | ||
"output_dir", | ||
|
@@ -294,7 +299,7 @@ def _bids_filter(value, parser): | |
default="qsiprep", | ||
choices=["qsiprep", "ukb", "hcpya"], | ||
help=( | ||
"Specify which pipeline was used to create the data specified as the bids_dir." | ||
"Specify which pipeline was used to create the data specified as the input_dir." | ||
"Not necessary to specify if the data was processed by QSIPrep. " | ||
"Other options include " | ||
'"ukb" for data processed with the UK BioBank minimal preprocessing pipeline and ' | ||
|
@@ -442,39 +447,84 @@ def parse_args(args=None, namespace=None): | |
f"total threads (--nthreads/--n_cpus={config.nipype.nprocs})" | ||
) | ||
|
||
bids_dir = config.execution.bids_dir | ||
input_dir = config.execution.input_dir | ||
output_dir = config.execution.output_dir | ||
work_dir = config.execution.work_dir | ||
version = config.environment.version | ||
|
||
# Update the config with an empty dict to trigger initialization of all config | ||
# sections (we used `init=False` above). | ||
# This must be done after cleaning the work directory, or we could delete an | ||
# open SQLite database | ||
config.from_dict({}) | ||
|
||
# Ensure input and output folders are not the same | ||
if output_dir == bids_dir: | ||
if output_dir == input_dir: | ||
parser.error( | ||
"The selected output folder is the same as the input BIDS folder. " | ||
"Please modify the output path (suggestion: %s)." | ||
% bids_dir | ||
% input_dir | ||
/ "derivatives" | ||
/ ("qsirecon-%s" % version.split("+")[0]) | ||
) | ||
|
||
if bids_dir in work_dir.parents: | ||
if input_dir in work_dir.parents: | ||
parser.error( | ||
"The selected working directory is a subdirectory of the input BIDS folder. " | ||
"Please modify the output path." | ||
) | ||
|
||
# Setup directories | ||
config.execution.log_dir = config.execution.output_dir / "logs" | ||
log_dir = output_dir / "logs" | ||
# Check and create output and working directories | ||
config.execution.log_dir.mkdir(exist_ok=True, parents=True) | ||
log_dir.mkdir(exist_ok=True, parents=True) | ||
work_dir.mkdir(exist_ok=True, parents=True) | ||
|
||
# Run ingression if necessary | ||
if config.workflow.input_type in ("hcpya", "ukb"): | ||
import os.path as op | ||
import shutil | ||
|
||
from ingress2qsirecon.data import load_resource | ||
from ingress2qsirecon.utils.functions import create_layout | ||
from ingress2qsirecon.utils.workflows import create_ingress2qsirecon_wf | ||
|
||
# Fake BIDS directory to be created | ||
config.execution.bids_dir = work_dir / "bids" | ||
|
||
# Make fake BIDS files | ||
bids_scaffold = str(load_resource("bids_scaffold")) | ||
if not op.exists(op.join(config.execution.bids_dir, "dataset_description.json")): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you switch this to use pathlib instead of op? I think we're going to try to consistently use it to be in line with nipreps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think I changed this, untested so far:
|
||
shutil.copytree( | ||
bids_scaffold, | ||
config.execution.bids_dir, | ||
dirs_exist_ok=True, | ||
) | ||
|
||
if config.execution.participant_label is None: | ||
participants_ingression = [] | ||
else: | ||
participants_ingression = list(config.execution.participant_label) | ||
layouts = create_layout( | ||
config.execution.input_dir, | ||
config.execution.bids_dir, | ||
config.workflow.input_type, | ||
participants_ingression, | ||
) | ||
|
||
# Create the ingression workflow | ||
wf = create_ingress2qsirecon_wf( | ||
layouts, | ||
base_dir=work_dir, | ||
) | ||
|
||
# Configure the nipype workflow | ||
wf.config["execution"]["crashdump_dir"] = str(log_dir) | ||
wf.run() | ||
else: | ||
config.execution.bids_dir = config.execution.input_dir | ||
|
||
# Update the config with an empty dict to trigger initialization of all config | ||
# sections (we used `init=False` above). | ||
# This must be done after cleaning the work directory, or we could delete an | ||
# open SQLite database | ||
config.from_dict({}) | ||
config.execution.log_dir = log_dir | ||
|
||
# Force initialization of the BIDSLayout | ||
config.execution.init() | ||
all_subjects = config.execution.layout.get_subjects() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great idea to add this to the docs