Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit d751eb8

Browse files
committed
wip: bidsy cli
1 parent 48c2de8 commit d751eb8

File tree

4 files changed

+55
-49
lines changed

4 files changed

+55
-49
lines changed

dmriprep/cli.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,51 @@
33
"""Console script for dmriprep."""
44
import sys
55
import click
6+
from . import run
7+
from . import io
8+
import os
69

710

811
@click.command()
9-
def main(args=None):
10-
"""Console script for dmriprep."""
11-
click.echo("Replace this message by putting your code into "
12-
"dmriprep.cli.main")
13-
click.echo("See click documentation at http://click.pocoo.org/")
12+
@click.option('--participant-label', help="The label(s) of the participant(s) that should be"
13+
"analyzed. The label corresponds to"
14+
"sub-<participant_label> from the BIDS spec (so it does"
15+
"not include 'sub-'). If this parameter is not provided"
16+
"all subjects will be analyzed. Multiple participants"
17+
"can be specified with a space separated list.",
18+
default=None
19+
)
20+
@click.argument('bids_dir',
21+
)
22+
@click.argument('output_dir',
23+
)
24+
@click.argument('analysis_level',
25+
type=click.Choice(['participant', 'group']),
26+
default='participant')
27+
def main(participant_label, bids_dir, output_dir, analysis_level="participant"):
28+
"""
29+
BIDS_DIR: The directory with the input dataset formatted according to the BIDS standard.
30+
31+
OUTPUT_DIR: The directory where the output files should be stored.
32+
If you are running a group level analysis, this folder
33+
should be prepopulated with the results of
34+
the participant level analysis.
35+
36+
ANALYSIS_LEVEL: Level of the analysis that will be performed. Multiple
37+
participant level analyses can be run independently
38+
(in parallel).
39+
"""
40+
41+
if analysis_level is not 'participant':
42+
raise NotImplementedError('The only valid analysis level for dmriprep is participant at the moment.')
43+
44+
inputs = io.get_BIDS_files(participant_label, bids_dir)
45+
46+
# for subject_id, subject_inputs in inputs:
47+
# run.run_dmriprep_pe(**subject_inputs,
48+
# working_dir=os.path.join(output_dir, 'scratch'),
49+
# out_dir=output_dir)
50+
click.echo('doing stuff {} {} {} {}'.format(participant_label, bids_dir, output_dir, analysis_level))
1451
return 0
1552

1653

dmriprep/dmriprep.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,3 @@
1111

1212

1313
mod_logger = logging.getLogger(__name__)
14-
15-
16-
17-
def pre_afq_individual(input_s3_keys, s3_prefix, out_bucket,
18-
in_bucket='fcp-indi', workdir=op.abspath('.')):
19-
input_files = fetch.download_register(
20-
subject_keys=input_s3_keys,
21-
bucket=in_bucket,
22-
directory=op.abspath(op.join(workdir, 'input')),
23-
)
24-
25-
move_t1_to_freesurfer(input_files.files['t1w'][0])
26-
27-
scratch_dir = op.join(workdir, 'scratch')
28-
out_dir = op.join(workdir, 'output')
29-
30-
run_dmriprep(
31-
dwi_file=input_files.files['dwi'][0],
32-
dwi_file_AP=input_files.files['epi_ap'][0],
33-
dwi_file_PA=input_files.files['epi_pa'][0],
34-
bvec_file=input_files.files['bvec'][0],
35-
bval_file=input_files.files['bval'][0],
36-
subjects_dir=op.dirname(input_files.files['t1w'][0]),
37-
working_dir=scratch_dir,
38-
out_dir=out_dir,
39-
)
40-
41-
out_files = []
42-
for root, dirs, filenames in os.walk(out_dir):
43-
for filename in filenames:
44-
rel_path = op.join(root, filename)
45-
if op.isfile(rel_path):
46-
out_files.append(rel_path.replace(out_dir + '/', '', 1))
47-
48-
s3_output = upload_to_s3(output_files=out_files,
49-
outdir=out_dir,
50-
bucket=out_bucket,
51-
prefix=s3_prefix,
52-
site=input_s3_keys.site,
53-
session=input_s3_keys.session,
54-
subject=input_s3_keys.subject)
55-
56-
return s3_output

dmriprep/io.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""
2+
BIDS-functions to return inputs for the run.py functions.
3+
4+
"""
5+
from glob import glob
6+
import os
7+
8+
def get_BIDS_files(subject_id, bids_input_directory):
9+
if not subject_id:
10+
subjects = glob(os.path.join(bids_input_directory, "*"))

dmriprep/run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def run_dmriprep_pe(dwi_file, dwi_file_AP, dwi_file_PA, bvec_file, bval_file,
264264
prep.inputs.inputnode.in_bval = bval_file
265265
eddy = prep.get_node('fsl_eddy')
266266
eddy.inputs.repol = True
267-
eddy.inputs.niter = 1 # TODO: change back to 5 when running for real
267+
eddy.inputs.niter = 1 # TODO: make this a parameter to the function with default 5
268268

269269
merge = pe.Node(fsl.Merge(dimension='t'), name="mergeAPPA")
270270
merge.inputs.in_files = [dwi_file_AP, dwi_file_PA]
@@ -429,7 +429,9 @@ def reportNodeFunc(dwi_corrected_file, eddy_rms, eddy_report,
429429
wf.connect(get_tensor, "color_fa_file", reportNode, 'color_fa_file')
430430

431431
wf.connect(reportNode, 'report', datasink, 'dmriprep.report.@report')
432+
wf.write_graph()
432433

434+
# TODO: take this out and just return workflow
433435
wf.run()
434436

435437
copyfile(bval_file, op.join(

0 commit comments

Comments
 (0)