Skip to content

Commit

Permalink
Merge pull request #51 from CoBrALab/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
Gab-D-G authored Jan 21, 2020
2 parents 1d87685 + 3e7e05b commit 625222f
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 49 deletions.
24 changes: 12 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ ENV export RABIES_VERSION=0.1.2 \

RUN export RABIES_VERSION=0.1.2 && \
export RABIES=$HOME/RABIES-${RABIES_VERSION} && \
#mkdir -p temp && \
#curl -L --retry 5 -o temp/RABIES.tar.gz https://github.com/CoBrALab/RABIES/archive/${RABIES_VERSION}.tar.gz && \
#cd temp && \
#tar zxf RABIES.tar.gz && \
#cd .. && \
#conda env create -f temp/RABIES-${RABIES_VERSION}/rabies_environment.yml && \
#bash temp/RABIES-${RABIES_VERSION}/install.sh && \
#rm -r temp && \
git clone https://github.com/CoBrALab/RABIES && \
mv RABIES $RABIES && \
conda env create -f $RABIES/rabies_environment.yml && \
bash $RABIES/install.sh && \
mkdir -p temp && \
curl -L --retry 5 -o temp/RABIES.tar.gz https://github.com/CoBrALab/RABIES/archive/${RABIES_VERSION}.tar.gz && \
cd temp && \
tar zxf RABIES.tar.gz && \
cd .. && \
conda env create -f temp/RABIES-${RABIES_VERSION}/rabies_environment.yml && \
bash temp/RABIES-${RABIES_VERSION}/install.sh && \
rm -r temp && \
#git clone https://github.com/CoBrALab/RABIES && \
#mv RABIES $RABIES && \
#conda env create -f $RABIES/rabies_environment.yml && \
#bash $RABIES/install.sh && \
DSURQE_100micron_labels=${RABIES}/template_files/DSURQE_100micron_labels.nii.gz && \
csv_labels=${RABIES}/template_files/DSURQE_40micron_R_mapping.csv && \
/home/rabies/miniconda-latest/envs/rabies/bin/python ${RABIES}/gen_masks.py $DSURQE_100micron_labels $csv_labels ${RABIES}/template_files/DSURQE_100micron
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ cluster options for running ants_dbm (options copied from twolevel_dbm.py)::
--local_threads LOCAL_THREADS
For local execution, how many subject-wise modelbuilds
to run in parallel, defaults to number of CPUs
(default: 2)
(default: 8)
--template_reg_script TEMPLATE_REG_SCRIPT
Registration script that will be used for registration
of the generated template to the provided atlas for
Expand All @@ -111,33 +111,33 @@ Specify Slice Timing Correction info that is fed to AFNI 3dTshift.:
Template files.:
--anat_template ANAT_TEMPLATE
Anatomical file for the commonspace template.
(default: /home/gabriel/RABIES-0.1.1/template_files/DS
URQE_100micron_average.nii.gz)
(default: /home/cic/desgab/RABIES-0.1.2/template_files
/DSURQE_100micron_average.nii.gz)
--brain_mask BRAIN_MASK
Brain mask for the template. (default: /home/gabriel/R
ABIES-0.1.1/template_files/DSURQE_100micron_mask.nii.g
z)
--WM_mask WM_MASK White matter mask for the template. (default: /home/ga
briel/RABIES-0.1.1/template_files/DSURQE_100micron_ero
ded_WM_mask.nii.gz)
--CSF_mask CSF_MASK CSF mask for the template. (default: /home/gabriel/RAB
IES-0.1.1/template_files/DSURQE_100micron_eroded_CSF_m
ask.nii.gz)
Brain mask for the template. (default: /home/cic/desga
b/RABIES-0.1.2/template_files/DSURQE_100micron_mask.ni
i.gz)
--WM_mask WM_MASK White matter mask for the template. (default: /home/ci
c/desgab/RABIES-0.1.2/template_files/DSURQE_100micron_
eroded_WM_mask.nii.gz)
--CSF_mask CSF_MASK CSF mask for the template. (default: /home/cic/desgab/
RABIES-0.1.2/template_files/DSURQE_100micron_eroded_CS
F_mask.nii.gz)
--vascular_mask VASCULAR_MASK
Can provide a mask of major blood vessels for
computing confound timeseries. The default mask was
generated by applying MELODIC ICA and selecting the
resulting component mapping onto major veins.
(Grandjean et al. 2020, NeuroImage; Beckmann et al.
2005) (default: /home/gabriel/RABIES-0.1.1/template_fi
les/vascular_mask.nii.gz)
--labels LABELS Atlas file with anatomical labels. (default: /home/gab
riel/RABIES-0.1.1/template_files/DSURQE_100micron_labe
ls.nii.gz)
2005) (default: /home/cic/desgab/RABIES-0.1.2/template
_files/vascular_mask.nii.gz)
--labels LABELS Atlas file with anatomical labels. (default: /home/cic
/desgab/RABIES-0.1.2/template_files/DSURQE_100micron_l
abels.nii.gz)
```

## Example execution command
## Command syntax
```
rabies nii_inputs/ rabies_outputs/ --bids_input -e -r light_SyN --template_reg_script light_SyN --TR 1.0s --cluster_type sge -p SGEGraph
```
Expand Down
15 changes: 9 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export RABIES=$HOME/RABIES-${RABIES_VERSION}
export PYTHONPATH="${PYTHONPATH}:$RABIES"

cd $HOME
#curl -L --retry 5 -o $HOME/RABIES.tar.gz https://github.com/CoBrALab/RABIES/archive/${RABIES_VERSION}.tar.gz
#tar zxf $HOME/RABIES.tar.gz
#rm $HOME/RABIES.tar.gz
git clone https://github.com/CoBrALab/RABIES
mv RABIES $RABIES
curl -L --retry 5 -o $HOME/RABIES.tar.gz https://github.com/CoBrALab/RABIES/archive/${RABIES_VERSION}.tar.gz
tar zxf $HOME/RABIES.tar.gz
rm $HOME/RABIES.tar.gz
#git clone https://github.com/CoBrALab/RABIES
#mv RABIES $RABIES

#creates an executable script to execute rabies
mkdir -p $RABIES/bin
Expand Down Expand Up @@ -44,5 +44,8 @@ csv_labels=$template_dir/DSURQE_40micron_R_mapping.csv
python $RABIES/gen_masks.py $DSURQE_100micron_labels $csv_labels $template_dir/DSURQE_100micron

# install twolevel_ants_dbm
git clone https://github.com/CobraLab/twolevel_ants_dbm $RABIES/twolevel_ants_dbm && \
git clone https://github.com/CoBrALab/twolevel_ants_dbm.git $RABIES/twolevel_ants_dbm
cd twolevel_ants_dbm
git checkout bde563f3ee017eb7f374b72e8599f2102a69c1da
cd ..
echo 'export PATH=$RABIES/twolevel_ants_dbm:$PATH' >> $HOME/.bashrc
12 changes: 10 additions & 2 deletions rabies/main_wf.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,25 @@ def init_unified_main_wf(data_dir_path, data_csv, output_folder, bids_input=Fals
#setting anat preprocessing nodes
anat_preproc_wf = init_anat_preproc_wf()

#calculate the number of anat scans that will be registered
num_anat=0
for sub in subject_list:
num_anat+=len(session_iter[sub])
if int(os.environ["ants_dbm_local_threads"])<num_anat:
num_anat=int(os.environ["ants_dbm_local_threads"])

commonspace_reg = pe.Node(Function(input_names=['file_list', 'output_folder'],
output_names=['ants_dbm_template'],
function=commonspace_reg_function),
name='commonspace_reg')
name='commonspace_reg', n_procs=num_anat)
commonspace_reg.inputs.output_folder = output_folder+'/commonspace_datasink/'

#execute the registration of the generate anatomical template with the provided atlas for labeling and masking
template_reg = pe.Node(Function(input_names=['reg_script', 'moving_image', 'fixed_image', 'anat_mask'],
output_names=['affine', 'warp', 'inverse_warp', 'warped_image'],
function=run_antsRegistration),
name='template_reg')
name='template_reg', mem_gb=3)
template_reg.plugin_args = {'qsub_args': '-pe smp %s' % (str(3*int(os.environ["min_proc"]))), 'overwrite': True}
template_reg.inputs.fixed_image = os.environ["template_anat"]
template_reg.inputs.anat_mask = os.environ["template_mask"]
template_reg.inputs.reg_script = template_reg_script
Expand Down
12 changes: 10 additions & 2 deletions rabies/preprocess_bold_pkg/bold_main_wf.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,17 +509,25 @@ def to_commonspace_transforms_prep(template_to_common_warp, template_to_common_a
joinsource='infosub_id',
joinfield=['file_list'])

#calculate the number of bold scans that will be registered
num_bold=0
for sub in subject_list:
num_bold+=(len(session_iter[sub])*len(run_iter[sub]))
if int(os.environ["ants_dbm_local_threads"])<num_bold:
num_bold=int(os.environ["ants_dbm_local_threads"])

commonspace_reg = pe.Node(Function(input_names=['file_list', 'output_folder'],
output_names=['ants_dbm_template'],
function=commonspace_reg_function),
name='commonspace_reg')
name='commonspace_reg', n_procs=num_bold)
commonspace_reg.inputs.output_folder = output_folder+'/commonspace_datasink/'

#execute the registration of the generate anatomical template with the provided atlas for labeling and masking
template_reg = pe.Node(Function(input_names=['reg_script', 'moving_image', 'fixed_image', 'anat_mask'],
output_names=['affine', 'warp', 'inverse_warp', 'warped_image'],
function=run_antsRegistration),
name='template_reg')
name='template_reg', mem_gb=3)
template_reg.plugin_args = {'qsub_args': '-pe smp %s' % (str(3*int(os.environ["min_proc"]))), 'overwrite': True}
template_reg.inputs.fixed_image = os.environ["template_anat"]
template_reg.inputs.anat_mask = os.environ["template_mask"]
template_reg.inputs.reg_script = template_reg_script
Expand Down
3 changes: 2 additions & 1 deletion rabies/preprocess_bold_pkg/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def init_bold_confs_wf(aCompCor_method='50%', name="bold_confs_wf"):
propagate_labels=pe.Node(MaskEPI(), name='prop_labels_EPI')
propagate_labels.inputs.name_spec='anat_labels'

confound_regression=pe.Node(ConfoundRegression(aCompCor_method=aCompCor_method), name='confound_regression')
confound_regression=pe.Node(ConfoundRegression(aCompCor_method=aCompCor_method), name='confound_regression', mem_gb=2)
confound_regression.plugin_args = {'qsub_args': '-pe smp %s' % (str(2*int(os.environ["min_proc"]))), 'overwrite': True}

workflow = pe.Workflow(name=name)
workflow.connect([
Expand Down
4 changes: 3 additions & 1 deletion rabies/preprocess_bold_pkg/hmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def init_bold_hmc_wf(name='bold_hmc_wf'):
movpar_file
CSV file with antsMotionCorr motion parameters
"""
import os

workflow = pe.Workflow(name=name)
inputnode = pe.Node(niu.IdentityInterface(fields=['bold_file', 'ref_image']),
name='inputnode')
Expand All @@ -39,7 +41,7 @@ def init_bold_hmc_wf(name='bold_hmc_wf'):

# Head motion correction (hmc)
motion_estimation = pe.Node(EstimateMotion(), name='ants_MC', mem_gb=3)
motion_estimation.plugin_args = {'qsub_args': '-pe smp 4', 'overwrite': True}
motion_estimation.plugin_args = {'qsub_args': '-pe smp %s' % (str(3*int(os.environ["min_proc"]))), 'overwrite': True}


workflow.connect([
Expand Down
2 changes: 1 addition & 1 deletion rabies/preprocess_bold_pkg/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def init_bold_reg_wf(coreg_script='SyN', name='bold_reg_wf'):
output_names=['affine_bold2anat', 'warp_bold2anat', 'inverse_warp_bold2anat', 'output_warped_bold'],
function=run_antsRegistration), name='EPI_Coregistration', mem_gb=3)
run_reg.inputs.reg_script=coreg_script
run_reg.plugin_args = {'qsub_args': '-pe smp 4', 'overwrite': True}
run_reg.plugin_args = {'qsub_args': '-pe smp %s' % (str(3*int(os.environ["min_proc"]))), 'overwrite': True}

workflow.connect([
(inputnode, run_reg, [
Expand Down
7 changes: 4 additions & 3 deletions rabies/preprocess_bold_pkg/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def init_bold_preproc_trans_wf(resampling_dim, name='bold_preproc_trans_wf'):
name='outputnode')


bold_transform = pe.Node(slice_applyTransforms(), name='bold_transform', mem_gb=3)
bold_transform = pe.Node(slice_applyTransforms(), name='bold_transform')
bold_transform.inputs.apply_motcorr = True
bold_transform.inputs.resampling_dim = resampling_dim
bold_transform.inputs.data_type = os.environ["rabies_data_type"]

merge = pe.Node(Merge(), name='merge', mem_gb=3)
merge.inputs.data_type = os.environ["rabies_data_type"]
#merge.plugin_args = {'qsub_args': '-pe smp 2 -l h_vmem=1G ', 'overwrite': True}
merge.plugin_args = {'qsub_args': '-pe smp %s' % (str(3*int(os.environ["min_proc"]))), 'overwrite': True}

# Generate a new BOLD reference
bold_reference_wf = init_bold_reference_wf()
Expand Down Expand Up @@ -66,14 +66,15 @@ def init_bold_commonspace_trans_wf(resampling_dim, name='bold_commonspace_trans_
niu.IdentityInterface(fields=['bold', 'bold_ref', 'brain_mask', 'WM_mask', 'CSF_mask', 'labels']),
name='outputnode')

bold_transform = pe.Node(slice_applyTransforms(), name='bold_transform', mem_gb=3)
bold_transform = pe.Node(slice_applyTransforms(), name='bold_transform')
bold_transform.inputs.apply_motcorr = True
bold_transform.inputs.ref_file = os.environ["template_anat"]
bold_transform.inputs.resampling_dim = resampling_dim
bold_transform.inputs.data_type = os.environ["rabies_data_type"]

merge = pe.Node(Merge(), name='merge', mem_gb=3)
merge.inputs.data_type = os.environ["rabies_data_type"]
merge.plugin_args = {'qsub_args': '-pe smp %s' % (str(3*int(os.environ["min_proc"]))), 'overwrite': True}

# Generate a new BOLD reference
bold_reference_wf = init_bold_reference_wf()
Expand Down
12 changes: 9 additions & 3 deletions rabies/preprocess_bold_pkg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ def init_bold_reference_wf(detect_dummy=False, name='gen_bold_ref'):
This interface implements the `following logic
<https://github.com/poldracklab/fmriprep/issues/873#issuecomment-349394544>
'''
validate = pe.Node(ValidateImage(), name='validate')
validate = pe.Node(ValidateImage(), name='validate', mem_gb=2)
validate.plugin_args = {'qsub_args': '-pe smp %s' % (str(2*int(os.environ["min_proc"]))), 'overwrite': True}

gen_ref = pe.Node(EstimateReferenceImage(detect_dummy=detect_dummy), name='gen_ref')
gen_ref = pe.Node(EstimateReferenceImage(detect_dummy=detect_dummy), name='gen_ref', mem_gb=2)
gen_ref.plugin_args = {'qsub_args': '-pe smp %s' % (str(2*int(os.environ["min_proc"]))), 'overwrite': True}

workflow.connect([
Expand Down Expand Up @@ -336,7 +336,13 @@ def _run_interface(self, runtime):
import nibabel as nb
import os
img=nb.load(self.inputs.in_file)
resample_image(nb.load(self.inputs.ref_file), self.inputs.data_type, img_dim=self.inputs.resampling_dim).to_filename('resampled.nii.gz')

if not self.inputs.resampling_dim=='origin':
resample_image(nb.load(self.inputs.ref_file), self.inputs.data_type, img_dim=self.inputs.resampling_dim).to_filename('resampled.nii.gz')
else:
shape=img.header.get_zooms()
dims="%sx%sx%s" % (shape[0],shape[1],shape[2])
resample_image(nb.load(self.inputs.ref_file), self.inputs.data_type, img_dim=dims).to_filename('resampled.nii.gz')

#tranforms is a list of transform files, set in order of call within antsApplyTransforms
transform_string=""
Expand Down

0 comments on commit 625222f

Please sign in to comment.