Skip to content

Commit 10eb826

Browse files
authored
Merge pull request #39 from neuroscout/datalad
Datalad compatability
2 parents 25f9c2d + 6767e52 commit 10eb826

File tree

4 files changed

+45
-33
lines changed

4 files changed

+45
-33
lines changed

Dockerfile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
# Use an poldracklab/fitlins as a parent image
22
FROM poldracklab/fitlins
33

4-
# Copy the current directory contents into the container at /app (using COPY instead of ADD to keep it lighter)
5-
COPY [".", "/src/neuroscout"]
6-
74
# Set user back to root
85
USER root
96
RUN chown -R root /src /work
107

8+
# Install neurodebian/datalad
9+
ARG DEBIAN_FRONTEND=noninteractive
10+
RUN apt-get update && apt-get install datalad -yq
11+
12+
RUN git config --global user.name "Neuroscout"
13+
RUN git config --global user.email "[email protected]"
14+
15+
1116
# Install additional neuroscout + dependencies
1217
RUN /bin/bash -c "source activate neuro \
1318
&& pip install -q --no-cache-dir -e /src/fitlins[all]" \
1419
&& sync
1520

21+
# Copy the current directory contents into the container at /app (using COPY instead of ADD to keep it lighter)
22+
COPY [".", "/src/neuroscout"]
23+
1624
RUN /bin/bash -c "source activate neuro \
1725
&& pip install -q --no-cache-dir -e /src/neuroscout/" \
1826
&& sync
1927

2028
RUN /bin/bash -c "source activate neuro \
21-
&& pip install -q --no-cache-dir -r /src/neuroscout/requirements.txt" \
29+
&& pip install -q --no-cache-dir --upgrade -r /src/neuroscout/requirements.txt" \
2230
&& sync
2331

24-
RUN /bin/bash -c "source activate neuro \
25-
&& pip install -q --no-cache-dir --upgrade git+https://github.com/INCF/pybids.git#egg=pybids"
2632

2733
WORKDIR /work
2834

neuroscout_cli/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
neuroscout
33
44
Usage:
5-
neuroscout run <bundle_id> [-dn -w <work_dir> -o <out_dir> -i <install_dir> --n-cpus=<n>]
5+
neuroscout run <bundle_id> [-dn -o <out_dir> -i <install_dir> --n-cpus=<n> --work-dir=<dir>]
66
neuroscout install <bundle_id> [-dn -i <install_dir>]
77
neuroscout ls <bundle_id>
88
neuroscout -h | --help
@@ -11,7 +11,7 @@
1111
Options:
1212
-i <install_dir> Directory to download dataset and bundle [default: .]
1313
-o <out_dir> Output directory [default: bundle_dir]
14-
-w <work_dir> Working directory
14+
--work-dir=<dir> Working directory
1515
--n-cpus=<n> Maximum number of threads across all processes [default: 1]
1616
-n, --no-download Dont download dataset (if available locally)
1717
-h --help Show this screen

neuroscout_cli/commands/install.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from neuroscout_cli.commands.base import Command
22
from neuroscout_cli import API_URL
3-
from datalad.api import install
3+
from datalad.api import install, get
44
from pathlib import Path
55
import requests
66
import json
@@ -59,31 +59,35 @@ def download_bundle(self):
5959
def download_data(self):
6060
self.download_bundle()
6161

62-
# logging.info("Installing dataset...")
63-
# Use datalad to install the raw BIDS dataset
64-
# install(source=self.resources['dataset_address'],
65-
# path=(self.dataset_dir).as_posix()).path
62+
remote_files = self.resources['func_paths'] + self.resources['mask_paths']
63+
remote_path = self.resources['preproc_address']
6664

67-
# Pre-fetch specific files from the original dataset?
68-
logging.info("Fetching remote resources...")
65+
deriv_dir = Path(self.dataset_dir) / 'derivatives'
6966

70-
# Fetch remote preprocessed files
71-
remote_path = self.resources['preproc_address']
72-
remote_files = self.resources['func_paths'] + self.resources['mask_paths']
67+
try:
68+
if not (deriv_dir / 'fmriprep').exists():
69+
# Use datalad to install the raw BIDS dataset
70+
install(source=remote_path,
71+
path=(deriv_dir / 'fmriprep').as_posix())
72+
73+
preproc_dir = deriv_dir / 'fmriprep' / 'fmriprep'
74+
get([(preproc_dir / f).as_posix() for f in remote_files])
75+
except Exception as e:
76+
message = e.failed[0]['message']
77+
if 'Failed to clone data from any candidate source URL' not in message[0]:
78+
raise ValueError("Datalad failed. Reason: {}".format(message))
7379

74-
preproc_dir = Path(self.dataset_dir) / 'derivatives' / 'fmriprep'
75-
preproc_dir.mkdir(exist_ok=True, parents=True)
80+
logging.info("Attempting HTTP download...")
81+
preproc_dir = deriv_dir / 'fmriprep'
82+
for i, resource in enumerate(remote_files):
83+
filename = preproc_dir / resource
84+
logging.info("{}/{}: {}".format(i+1, len(remote_files), resource))
7685

77-
for i, resource in enumerate(remote_files):
78-
logging.info("{}/{}: {}".format(i+1, len(remote_files), resource))
79-
filename = preproc_dir / resource
80-
if not filename.exists():
81-
filename.parents[0].mkdir(exist_ok=True, parents=True)
82-
url = remote_path + '/' + resource
83-
download_file(url, filename)
86+
if not filename.exists():
87+
filename.parents[0].mkdir(exist_ok=True, parents=True)
88+
download_file(remote_path + '/' + resource, filename)
8489

85-
desc = {'Name': self.dataset_dir.parts[0],
86-
'BIDSVersion': '1.0'}
90+
desc = {'Name': self.dataset_dir.parts[0], 'BIDSVersion': '1.0'}
8791

8892
with (self.dataset_dir / 'dataset_description.json').open('w') as f:
8993
json.dump(desc, f)

neuroscout_cli/commands/run.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def run(self):
2929
tmp_out,
3030
'dataset',
3131
'--model={}'.format((bundle_path / 'model.json').absolute().as_posix()),
32-
'--exclude=.*neuroscout/(?!{}).*'.format(bundle_path.parts[-1])
32+
'--exclude=(neuroscout/(?!{})|fmriprep.*$(?<=tsv)|/.git)'.format(bundle_path.parts[-1])
3333
]
3434

3535
# Fitlins invalid keys
36-
invalid = ['--no-download', '--version', '--help', '-i']
36+
invalid = ['--no-download', '--version', '--help', '-i', 'run', '<bundle_id>']
3737
for k in invalid:
3838
self.options.pop(k, None)
3939

@@ -42,8 +42,10 @@ def run(self):
4242
if name.startswith('--'):
4343
if value is True:
4444
fitlins_args.append('{}'.format(name))
45-
elif name.startswith('-'):
46-
if value is not None:
45+
if value is not None and value is not False:
46+
fitlins_args.append('{}={}'.format(name, value))
47+
else:
48+
if value is not False and value is not None:
4749
fitlins_args.append('{} {}'.format(name, value))
4850

4951
bids.config.set_options(loop_preproc=True)

0 commit comments

Comments
 (0)