Skip to content
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

Various fixes that make pymp2rage Docker work with latest fmriprep/et… #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@ RUN bash -c "source activate neuro && pip install lxml --upgrade"
RUN apt-get update -qq && apt-get install -y python python-pip python-dev build-essential software-properties-common openjdk-8-jdk
RUN ln -svT "/usr/lib/jvm/java-8-openjdk-$(dpkg --print-architecture)" /docker-java-home
ENV JAVA_HOME /docker-java-home
ENV JCC_JDK /docker-java-home
ENV JCC_JDK /docker-java-home
RUN apt-get install -y jcc

COPY nighres /nighres
COPY nighres /nighres

RUN cd /nighres \
&& python3 -m pip install --upgrade pip jcc \
&& ./build.sh \
&& bash -c "source activate neuro && pip install jcc" \
&& bash -c "./build_conda.sh neuro" \
&& bash -c "source activate neuro && python setup.py develop"

COPY ./analysis /src
COPY nipype.cfg /root/.nipype/nipype.cfg

RUN bash -c "source activate neuro && pip uninstall -y pandas && pip install pandas==0.23" \
&& bash -c "source activate neuro && pip uninstall -y templateflow && pip install templateflow"

COPY ./fmriprep /fmriprep
RUN bash -c "source activate neuro && pip uninstall -y fmriprep && cd /fmriprep && python setup.py develop"

Expand All @@ -53,3 +56,5 @@ RUN bash -c "source activate neuro && pip uninstall -y pybids && cd /pybids && p
COPY spynoza /spynoza
RUN bash -c "source activate neuro && pip uninstall -y spynoza && cd /pybids && python setup.py develop"

RUN bash -c "source activate neuro && pip install scikit-image --upgrade"
RUN bash -c "source activate neuro && pip install templateflow --upgrade"
2 changes: 1 addition & 1 deletion analysis/combine_scans.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
from fmriprep.interfaces import DerivativesDataSink
from bids import BIDSLayout
from fmriprep.interfaces import DerivativesDataSink
import re
import pandas as pd
import os
Expand Down
5 changes: 2 additions & 3 deletions analysis/mask_mp2rage.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def main(sourcedata,
if session is None:
session = '.*'

derivatives_layout = BIDSLayout(os.path.join(derivatives, 'averaged_mp2rages'))
derivatives_layout = BIDSLayout(os.path.join(derivatives, 'averaged_mp2rages'), validate=False)

inv2 = get_bids_file(derivatives_layout,
subject,
Expand Down Expand Up @@ -232,8 +232,7 @@ def init_masking_wf(name='mask_wf',
keep_dtype=False,
out_path_base='masked_mp2rages',
suffix='T1map',
desc='masked',
space='average'),
desc='masked'),
name='ds_t1map')

wf.connect(inputnode, 't1map', ds_t1map, 'source_file')
Expand Down
23 changes: 15 additions & 8 deletions analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def get_inv(mp2rage_parameters, inv=1, echo=1):
def fit_mp2rage(mp2rage_parameters, return_images=['t1w_uni', 't1map']):
import pymp2rage
import os
print(mp2rage_parameters)

if 'echo_times' in mp2rage_parameters:
mp2rage = pymp2rage.MEMP2RAGE(**mp2rage_parameters)
Expand All @@ -33,29 +34,33 @@ def get_mp2rage_pars(sourcedata, subject, session, acquisition):
from bids import BIDSLayout
import re
import os
import os.path as op
import glob
import json
import numpy as np

layout = BIDSLayout(sourcedata)
layout = BIDSLayout(sourcedata,
validate=False)

mp2rage_files = layout.get(subject=subject,
session=session,
acquisition=acquisition,
suffix='MPRAGE',
extensions=['.nii', '.nii.gz'])

print(mp2rage_files)

reg = re.compile('.*/sub-(?P<subject>.+)_ses-(?P<session>.+)_acq-(?P<acquisition>.+)_inv-(?P<inv>[0-9]+)(_echo-(?P<echo>[0-9]+))?(_part-(?P<part>.+))?_MPRAGE.(?P<extension>nii|nii\.gz|json)')

data = []
for file in mp2rage_files:
print(file.filename)
if not reg.match(file.filename):
print('ERROR WITH {}'.format(file))
data.append(reg.match(file.filename).groupdict())
data[-1]['filename'] = file.filename
print(file.path)
if not reg.match(file.path):
print('ERROR WITH {}'.format(file.path))
data.append(reg.match(file.path).groupdict())
data[-1]['filename'] = file.path
data = pd.DataFrame(data)
print(data)

folder = os.path.dirname(data.iloc[0].filename)
json_files = glob.glob(os.path.join(folder, '*.json'))
Expand All @@ -68,7 +73,9 @@ def get_mp2rage_pars(sourcedata, subject, session, acquisition):
json_data[-1].update(json.load(f))

json_data = pd.DataFrame(json_data)
json_data.drop(columns=['part', 'extension'], inplace=True)
print(json_data)
json_data.drop('part', axis=1, inplace=True)
json_data.drop('extension', axis=1, inplace=True)
data = data.merge(json_data, on=['subject', 'session', 'acquisition', 'inv', 'echo'])

data.drop(columns=['subject', 'session'])
Expand All @@ -82,7 +89,7 @@ def get_mp2rage_pars(sourcedata, subject, session, acquisition):
B1map = layout.get(subject=subject, session=session, suffix='B1map', extensions=['.nii', '.nii.gz'])

if len(B1map) > 0:
B1map = B1map[0].filename
B1map = B1map[0].path
data['B1map'] = B1map

multi_echo_bool = len(data.loc[acquisition,2, :, 'mag']) > 2
Expand Down
2 changes: 1 addition & 1 deletion fmriprep
Submodule fmriprep updated 101 files
4 changes: 4 additions & 0 deletions go
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export FREESURFER_HOME=/home/freesurfer/license.txt
export DERIVATIVES=/home/shared/2018/visual/SB-prep/SB-ref/derivatives/mp2rage_preproc_out
export SOURCEDATA=/home/shared/2018/visual/SB-prep/SB-ref/sourcedata
docker-compose run --rm mp2rage_preproc

2 changes: 1 addition & 1 deletion nighres
2 changes: 1 addition & 1 deletion pybids
Submodule pybids updated 358 files
2 changes: 1 addition & 1 deletion spynoza
Submodule spynoza updated 361 files