Skip to content

Commit 625222f

Browse files
authored
Merge pull request #51 from CoBrALab/updates
Updates
2 parents 1d87685 + 3e7e05b commit 625222f

File tree

10 files changed

+78
-49
lines changed

10 files changed

+78
-49
lines changed

Dockerfile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,18 @@ ENV export RABIES_VERSION=0.1.2 \
130130

131131
RUN export RABIES_VERSION=0.1.2 && \
132132
export RABIES=$HOME/RABIES-${RABIES_VERSION} && \
133-
#mkdir -p temp && \
134-
#curl -L --retry 5 -o temp/RABIES.tar.gz https://github.com/CoBrALab/RABIES/archive/${RABIES_VERSION}.tar.gz && \
135-
#cd temp && \
136-
#tar zxf RABIES.tar.gz && \
137-
#cd .. && \
138-
#conda env create -f temp/RABIES-${RABIES_VERSION}/rabies_environment.yml && \
139-
#bash temp/RABIES-${RABIES_VERSION}/install.sh && \
140-
#rm -r temp && \
141-
git clone https://github.com/CoBrALab/RABIES && \
142-
mv RABIES $RABIES && \
143-
conda env create -f $RABIES/rabies_environment.yml && \
144-
bash $RABIES/install.sh && \
133+
mkdir -p temp && \
134+
curl -L --retry 5 -o temp/RABIES.tar.gz https://github.com/CoBrALab/RABIES/archive/${RABIES_VERSION}.tar.gz && \
135+
cd temp && \
136+
tar zxf RABIES.tar.gz && \
137+
cd .. && \
138+
conda env create -f temp/RABIES-${RABIES_VERSION}/rabies_environment.yml && \
139+
bash temp/RABIES-${RABIES_VERSION}/install.sh && \
140+
rm -r temp && \
141+
#git clone https://github.com/CoBrALab/RABIES && \
142+
#mv RABIES $RABIES && \
143+
#conda env create -f $RABIES/rabies_environment.yml && \
144+
#bash $RABIES/install.sh && \
145145
DSURQE_100micron_labels=${RABIES}/template_files/DSURQE_100micron_labels.nii.gz && \
146146
csv_labels=${RABIES}/template_files/DSURQE_40micron_R_mapping.csv && \
147147
/home/rabies/miniconda-latest/envs/rabies/bin/python ${RABIES}/gen_masks.py $DSURQE_100micron_labels $csv_labels ${RABIES}/template_files/DSURQE_100micron

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ cluster options for running ants_dbm (options copied from twolevel_dbm.py)::
8888
--local_threads LOCAL_THREADS
8989
For local execution, how many subject-wise modelbuilds
9090
to run in parallel, defaults to number of CPUs
91-
(default: 2)
91+
(default: 8)
9292
--template_reg_script TEMPLATE_REG_SCRIPT
9393
Registration script that will be used for registration
9494
of the generated template to the provided atlas for
@@ -111,33 +111,33 @@ Specify Slice Timing Correction info that is fed to AFNI 3dTshift.:
111111
Template files.:
112112
--anat_template ANAT_TEMPLATE
113113
Anatomical file for the commonspace template.
114-
(default: /home/gabriel/RABIES-0.1.1/template_files/DS
115-
URQE_100micron_average.nii.gz)
114+
(default: /home/cic/desgab/RABIES-0.1.2/template_files
115+
/DSURQE_100micron_average.nii.gz)
116116
--brain_mask BRAIN_MASK
117-
Brain mask for the template. (default: /home/gabriel/R
118-
ABIES-0.1.1/template_files/DSURQE_100micron_mask.nii.g
119-
z)
120-
--WM_mask WM_MASK White matter mask for the template. (default: /home/ga
121-
briel/RABIES-0.1.1/template_files/DSURQE_100micron_ero
122-
ded_WM_mask.nii.gz)
123-
--CSF_mask CSF_MASK CSF mask for the template. (default: /home/gabriel/RAB
124-
IES-0.1.1/template_files/DSURQE_100micron_eroded_CSF_m
125-
ask.nii.gz)
117+
Brain mask for the template. (default: /home/cic/desga
118+
b/RABIES-0.1.2/template_files/DSURQE_100micron_mask.ni
119+
i.gz)
120+
--WM_mask WM_MASK White matter mask for the template. (default: /home/ci
121+
c/desgab/RABIES-0.1.2/template_files/DSURQE_100micron_
122+
eroded_WM_mask.nii.gz)
123+
--CSF_mask CSF_MASK CSF mask for the template. (default: /home/cic/desgab/
124+
RABIES-0.1.2/template_files/DSURQE_100micron_eroded_CS
125+
F_mask.nii.gz)
126126
--vascular_mask VASCULAR_MASK
127127
Can provide a mask of major blood vessels for
128128
computing confound timeseries. The default mask was
129129
generated by applying MELODIC ICA and selecting the
130130
resulting component mapping onto major veins.
131131
(Grandjean et al. 2020, NeuroImage; Beckmann et al.
132-
2005) (default: /home/gabriel/RABIES-0.1.1/template_fi
133-
les/vascular_mask.nii.gz)
134-
--labels LABELS Atlas file with anatomical labels. (default: /home/gab
135-
riel/RABIES-0.1.1/template_files/DSURQE_100micron_labe
136-
ls.nii.gz)
132+
2005) (default: /home/cic/desgab/RABIES-0.1.2/template
133+
_files/vascular_mask.nii.gz)
134+
--labels LABELS Atlas file with anatomical labels. (default: /home/cic
135+
/desgab/RABIES-0.1.2/template_files/DSURQE_100micron_l
136+
abels.nii.gz)
137137
138138
```
139139

140-
## Example execution command
140+
## Command syntax
141141
```
142142
rabies nii_inputs/ rabies_outputs/ --bids_input -e -r light_SyN --template_reg_script light_SyN --TR 1.0s --cluster_type sge -p SGEGraph
143143
```

install.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ export RABIES=$HOME/RABIES-${RABIES_VERSION}
66
export PYTHONPATH="${PYTHONPATH}:$RABIES"
77

88
cd $HOME
9-
#curl -L --retry 5 -o $HOME/RABIES.tar.gz https://github.com/CoBrALab/RABIES/archive/${RABIES_VERSION}.tar.gz
10-
#tar zxf $HOME/RABIES.tar.gz
11-
#rm $HOME/RABIES.tar.gz
12-
git clone https://github.com/CoBrALab/RABIES
13-
mv RABIES $RABIES
9+
curl -L --retry 5 -o $HOME/RABIES.tar.gz https://github.com/CoBrALab/RABIES/archive/${RABIES_VERSION}.tar.gz
10+
tar zxf $HOME/RABIES.tar.gz
11+
rm $HOME/RABIES.tar.gz
12+
#git clone https://github.com/CoBrALab/RABIES
13+
#mv RABIES $RABIES
1414

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

4646
# install twolevel_ants_dbm
47-
git clone https://github.com/CobraLab/twolevel_ants_dbm $RABIES/twolevel_ants_dbm && \
47+
git clone https://github.com/CoBrALab/twolevel_ants_dbm.git $RABIES/twolevel_ants_dbm
48+
cd twolevel_ants_dbm
49+
git checkout bde563f3ee017eb7f374b72e8599f2102a69c1da
50+
cd ..
4851
echo 'export PATH=$RABIES/twolevel_ants_dbm:$PATH' >> $HOME/.bashrc

rabies/main_wf.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,25 @@ def init_unified_main_wf(data_dir_path, data_csv, output_folder, bids_input=Fals
233233
#setting anat preprocessing nodes
234234
anat_preproc_wf = init_anat_preproc_wf()
235235

236+
#calculate the number of anat scans that will be registered
237+
num_anat=0
238+
for sub in subject_list:
239+
num_anat+=len(session_iter[sub])
240+
if int(os.environ["ants_dbm_local_threads"])<num_anat:
241+
num_anat=int(os.environ["ants_dbm_local_threads"])
242+
236243
commonspace_reg = pe.Node(Function(input_names=['file_list', 'output_folder'],
237244
output_names=['ants_dbm_template'],
238245
function=commonspace_reg_function),
239-
name='commonspace_reg')
246+
name='commonspace_reg', n_procs=num_anat)
240247
commonspace_reg.inputs.output_folder = output_folder+'/commonspace_datasink/'
241248

242249
#execute the registration of the generate anatomical template with the provided atlas for labeling and masking
243250
template_reg = pe.Node(Function(input_names=['reg_script', 'moving_image', 'fixed_image', 'anat_mask'],
244251
output_names=['affine', 'warp', 'inverse_warp', 'warped_image'],
245252
function=run_antsRegistration),
246-
name='template_reg')
253+
name='template_reg', mem_gb=3)
254+
template_reg.plugin_args = {'qsub_args': '-pe smp %s' % (str(3*int(os.environ["min_proc"]))), 'overwrite': True}
247255
template_reg.inputs.fixed_image = os.environ["template_anat"]
248256
template_reg.inputs.anat_mask = os.environ["template_mask"]
249257
template_reg.inputs.reg_script = template_reg_script

rabies/preprocess_bold_pkg/bold_main_wf.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,17 +509,25 @@ def to_commonspace_transforms_prep(template_to_common_warp, template_to_common_a
509509
joinsource='infosub_id',
510510
joinfield=['file_list'])
511511

512+
#calculate the number of bold scans that will be registered
513+
num_bold=0
514+
for sub in subject_list:
515+
num_bold+=(len(session_iter[sub])*len(run_iter[sub]))
516+
if int(os.environ["ants_dbm_local_threads"])<num_bold:
517+
num_bold=int(os.environ["ants_dbm_local_threads"])
518+
512519
commonspace_reg = pe.Node(Function(input_names=['file_list', 'output_folder'],
513520
output_names=['ants_dbm_template'],
514521
function=commonspace_reg_function),
515-
name='commonspace_reg')
522+
name='commonspace_reg', n_procs=num_bold)
516523
commonspace_reg.inputs.output_folder = output_folder+'/commonspace_datasink/'
517524

518525
#execute the registration of the generate anatomical template with the provided atlas for labeling and masking
519526
template_reg = pe.Node(Function(input_names=['reg_script', 'moving_image', 'fixed_image', 'anat_mask'],
520527
output_names=['affine', 'warp', 'inverse_warp', 'warped_image'],
521528
function=run_antsRegistration),
522-
name='template_reg')
529+
name='template_reg', mem_gb=3)
530+
template_reg.plugin_args = {'qsub_args': '-pe smp %s' % (str(3*int(os.environ["min_proc"]))), 'overwrite': True}
523531
template_reg.inputs.fixed_image = os.environ["template_anat"]
524532
template_reg.inputs.anat_mask = os.environ["template_mask"]
525533
template_reg.inputs.reg_script = template_reg_script

rabies/preprocess_bold_pkg/confounds.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def init_bold_confs_wf(aCompCor_method='50%', name="bold_confs_wf"):
3131
propagate_labels=pe.Node(MaskEPI(), name='prop_labels_EPI')
3232
propagate_labels.inputs.name_spec='anat_labels'
3333

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

3637
workflow = pe.Workflow(name=name)
3738
workflow.connect([

rabies/preprocess_bold_pkg/hmc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def init_bold_hmc_wf(name='bold_hmc_wf'):
3030
movpar_file
3131
CSV file with antsMotionCorr motion parameters
3232
"""
33+
import os
34+
3335
workflow = pe.Workflow(name=name)
3436
inputnode = pe.Node(niu.IdentityInterface(fields=['bold_file', 'ref_image']),
3537
name='inputnode')
@@ -39,7 +41,7 @@ def init_bold_hmc_wf(name='bold_hmc_wf'):
3941

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

4446

4547
workflow.connect([

rabies/preprocess_bold_pkg/registration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def init_bold_reg_wf(coreg_script='SyN', name='bold_reg_wf'):
5959
output_names=['affine_bold2anat', 'warp_bold2anat', 'inverse_warp_bold2anat', 'output_warped_bold'],
6060
function=run_antsRegistration), name='EPI_Coregistration', mem_gb=3)
6161
run_reg.inputs.reg_script=coreg_script
62-
run_reg.plugin_args = {'qsub_args': '-pe smp 4', 'overwrite': True}
62+
run_reg.plugin_args = {'qsub_args': '-pe smp %s' % (str(3*int(os.environ["min_proc"]))), 'overwrite': True}
6363

6464
workflow.connect([
6565
(inputnode, run_reg, [

rabies/preprocess_bold_pkg/resampling.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ def init_bold_preproc_trans_wf(resampling_dim, name='bold_preproc_trans_wf'):
2121
name='outputnode')
2222

2323

24-
bold_transform = pe.Node(slice_applyTransforms(), name='bold_transform', mem_gb=3)
24+
bold_transform = pe.Node(slice_applyTransforms(), name='bold_transform')
2525
bold_transform.inputs.apply_motcorr = True
2626
bold_transform.inputs.resampling_dim = resampling_dim
2727
bold_transform.inputs.data_type = os.environ["rabies_data_type"]
2828

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

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

69-
bold_transform = pe.Node(slice_applyTransforms(), name='bold_transform', mem_gb=3)
69+
bold_transform = pe.Node(slice_applyTransforms(), name='bold_transform')
7070
bold_transform.inputs.apply_motcorr = True
7171
bold_transform.inputs.ref_file = os.environ["template_anat"]
7272
bold_transform.inputs.resampling_dim = resampling_dim
7373
bold_transform.inputs.data_type = os.environ["rabies_data_type"]
7474

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

7879
# Generate a new BOLD reference
7980
bold_reference_wf = init_bold_reference_wf()

rabies/preprocess_bold_pkg/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ def init_bold_reference_wf(detect_dummy=False, name='gen_bold_ref'):
131131
This interface implements the `following logic
132132
<https://github.com/poldracklab/fmriprep/issues/873#issuecomment-349394544>
133133
'''
134-
validate = pe.Node(ValidateImage(), name='validate')
134+
validate = pe.Node(ValidateImage(), name='validate', mem_gb=2)
135135
validate.plugin_args = {'qsub_args': '-pe smp %s' % (str(2*int(os.environ["min_proc"]))), 'overwrite': True}
136136

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

140140
workflow.connect([
@@ -336,7 +336,13 @@ def _run_interface(self, runtime):
336336
import nibabel as nb
337337
import os
338338
img=nb.load(self.inputs.in_file)
339-
resample_image(nb.load(self.inputs.ref_file), self.inputs.data_type, img_dim=self.inputs.resampling_dim).to_filename('resampled.nii.gz')
339+
340+
if not self.inputs.resampling_dim=='origin':
341+
resample_image(nb.load(self.inputs.ref_file), self.inputs.data_type, img_dim=self.inputs.resampling_dim).to_filename('resampled.nii.gz')
342+
else:
343+
shape=img.header.get_zooms()
344+
dims="%sx%sx%s" % (shape[0],shape[1],shape[2])
345+
resample_image(nb.load(self.inputs.ref_file), self.inputs.data_type, img_dim=dims).to_filename('resampled.nii.gz')
340346

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

0 commit comments

Comments
 (0)