Skip to content

Commit 80e9763

Browse files
Add bet4animal (#303)
* bet4animal
1 parent e5a14bb commit 80e9763

19 files changed

+1200
-53
lines changed

Dockerfile_macapype_env_nomcr

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -74,47 +74,6 @@ RUN echo '{ \
7474
\n ] \
7575
\n}' > /neurodocker/neurodocker_specs.json
7676

77-
################################################## Install FSL
78-
ENV FSLDIR="/opt/fsl-5.0.10" \
79-
PATH="/opt/fsl-5.0.10/bin:$PATH" \
80-
FSLOUTPUTTYPE="NIFTI_GZ" \
81-
FSLMULTIFILEQUIT="TRUE" \
82-
FSLTCLSH="/opt/fsl-5.0.10/bin/fsltclsh" \
83-
FSLWISH="/opt/fsl-5.0.10/bin/fslwish" \
84-
FSLLOCKDIR="" \
85-
FSLMACHINELIST="" \
86-
FSLREMOTECALL="" \
87-
FSLGECUDAQ="cuda.q"
88-
RUN apt-get install -y -q --no-install-recommends \
89-
bc \
90-
dc \
91-
file \
92-
libfontconfig1 \
93-
libfreetype6 \
94-
libgl1-mesa-dev \
95-
libgl1-mesa-dri \
96-
libglu1-mesa-dev \
97-
libgomp1 \
98-
libice6 \
99-
libxcursor1 \
100-
libxft2 \
101-
libxinerama1 \
102-
libxrandr2 \
103-
libxrender1 \
104-
libxt6 \
105-
sudo \
106-
wget \
107-
&& echo "Downloading FSL ..." \
108-
&& mkdir -p /opt/fsl-5.0.10 \
109-
&& curl -fsSL --retry 5 https://fsl.fmrib.ox.ac.uk/fsldownloads/fsl-5.0.10-centos6_64.tar.gz \
110-
| tar -xz -C /opt/fsl-5.0.10 --strip-components 1 \
111-
&& sed -i '$iecho Some packages in this Docker container are non-free' $ND_ENTRYPOINT \
112-
&& sed -i '$iecho If you are considering commercial use of this container, please consult the relevant license:' $ND_ENTRYPOINT \
113-
&& sed -i '$iecho https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Licence' $ND_ENTRYPOINT \
114-
&& sed -i '$isource $FSLDIR/etc/fslconf/fsl.sh' $ND_ENTRYPOINT \
115-
&& echo "Installing FSL conda environment ..." \
116-
&& bash /opt/fsl-5.0.10/etc/fslconf/fslpython_install.sh -f /opt/fsl-5.0.10
117-
11877
################################################## Install AFNI
11978
ENV PATH="/opt/afni-latest:$PATH" \
12079
AFNI_PLUGINPATH="/opt/afni-latest"
@@ -155,17 +114,26 @@ RUN ls -l /usr/lib/x86_64-linux-gnu
155114
RUN ln -s /usr/lib/x86_64-linux-gnu/libXpm.so.4.11.0 /usr/lib/x86_64-linux-gnu/libXp.so.6
156115

157116
################################################## Install ANTS
158-
ENV ANTSPATH="/opt/ants-2.3.1" \
159-
PATH="/opt/ants-2.3.1:$PATH"
160-
RUN echo "Downloading ANTs ..." \
161-
&& mkdir -p /opt/ants-2.3.1 \
162-
&& curl -fsSL --retry 5 https://dl.dropbox.com/s/1xfhydsf4t4qoxg/ants-Linux-centos6_x86_64-v2.3.1.tar.gz \
163-
| tar -xz -C /opt/ants-2.3.1 --strip-components 1
117+
ENV ANTSPATH="/opt/ants-2.4.3/" \
118+
PATH="/opt/ants-2.4.3:$PATH"
119+
RUN apt-get update -qq \
120+
&& apt-get install -y -q --no-install-recommends \
121+
ca-certificates \
122+
curl \
123+
unzip \
124+
&& rm -rf /var/lib/apt/lists/* \
125+
&& echo "Downloading ANTs ..." \
126+
&& curl -fsSL -o ants.zip https://github.com/ANTsX/ANTs/releases/download/v2.4.3/ants-2.4.3-centos7-X64-gcc.zip \
127+
&& unzip ants.zip -d /opt \
128+
&& mv /opt/ants-2.4.3/bin/* /opt/ants-2.4.3 \
129+
&& rm ants.zip
164130

165131
######################## NiftiReg
132+
RUN apt-get update -qq
166133
RUN apt-get install --yes --no-install-recommends \
167-
ca-certificates cmake gcc g++ git make \
168-
&& git clone https://github.com/KCL-BMEIS/niftyreg.git /tmp/niftyreg-src \
134+
ca-certificates cmake gcc g++ git make
135+
136+
RUN git clone https://github.com/KCL-BMEIS/niftyreg.git /tmp/niftyreg-src \
169137
&& mkdir /tmp/niftyreg-build \
170138
&& cd /tmp/niftyreg-build \
171139
&& cmake -DCMAKE_INSTALL_PREFIX=/opt/niftyreg /tmp/niftyreg-src \
@@ -219,6 +187,30 @@ RUN python -m pip install -U pillow
219187
#RUN pip install -U pillow
220188
RUN python -c "import PIL; print(PIL.__version__)"
221189

190+
################################################## Install FSL
191+
192+
ENV FSLDIR "/usr/local/fsl"
193+
ENV DEBIAN_FRONTEND "noninteractive"
194+
ENV LANG "en_GB.UTF-8"
195+
196+
RUN apt update -y && \
197+
apt upgrade -y && \
198+
apt install -y \
199+
wget \
200+
file \
201+
dc \
202+
mesa-utils \
203+
pulseaudio \
204+
libquadmath0 \
205+
libgtk2.0-0 \
206+
libgomp1
207+
208+
RUN wget https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/releases/fslinstaller.py
209+
RUN python -m pip install readline
210+
RUN python ./fslinstaller.py -d /usr/local/fsl/
211+
212+
ENTRYPOINT [ "sh", "-c", ". /usr/local/fsl/etc/fslconf/fsl.sh && /bin/bash" ]
213+
222214
################################################## Finishing
223215
RUN apt-get clean \
224216
&& rm -rf /var/lib/apt/lists/*

macapype/nodes/extract_brain.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,96 @@ def _list_outputs(self):
482482
return outputs
483483

484484

485+
# Bet4Animal
486+
class Bet4AnimalInputSpec(CommandLineInputSpec):
487+
488+
import os
489+
490+
in_file = File(
491+
exists=True,
492+
desc='T1 image to map',
493+
mandatory=True, position=0, argstr="%s")
494+
495+
out_file = File(
496+
desc='name of output skull stripped image',
497+
name_source=["in_file"],
498+
name_template="%s_brain",
499+
keep_extension=True,
500+
hash_files=False,
501+
position=1, argstr="%s")
502+
503+
outline = traits.Bool(
504+
False, usedefault=True, desc='outline',
505+
argstr="--outline", mandatory=False)
506+
507+
mask = traits.Bool(
508+
True, usedefault=True, desc='mask',
509+
argstr="--mask", mandatory=False)
510+
511+
label = traits.Enum(
512+
2, 0, 1, 3, usedefault=True, desc="label (default 2 = macaque)",
513+
argstr="-z %d", mandatory=True)
514+
515+
robust = traits.Bool(
516+
True, usedefault=True,
517+
desc='robust brain centre estimation (iterates BET several times)',
518+
argstr="-R",)
519+
520+
f = traits.Float(
521+
desc='fractional intensity threshold (0->1); default=0.5; \
522+
smaller values give larger brain outline estimates', argstr="-f %f",
523+
mandatory=False)
524+
525+
526+
class Bet4AnimalOutputSpec(TraitedSpec):
527+
528+
out_file = File(
529+
exists=True,
530+
desc="masked T1 from hd-bet")
531+
532+
mask_file = File(
533+
exists=True,
534+
desc="brain mask from hd-bet")
535+
536+
537+
class Bet4Animal(CommandLine):
538+
"""
539+
Description: Atlas based BrainExtraction
540+
541+
Inputs:
542+
543+
Mandatory:
544+
545+
Outputs:
546+
547+
brain_file:
548+
File, "extracted brain from atlas_brex"
549+
550+
"""
551+
input_spec = Bet4AnimalInputSpec
552+
output_spec = Bet4AnimalOutputSpec
553+
554+
_cmd = 'bet4animal '
555+
556+
def _gen_maskfilename(self):
557+
from nipype.utils.filemanip import split_filename as split_f
558+
# Generate default mask filename
559+
if isdefined(self.inputs.in_file) and self.inputs.mask is True:
560+
path, fname, ext = split_f(self.inputs.in_file)
561+
mask_file = fname + "_brain_mask" + ext
562+
return os.path.abspath(mask_file)
563+
564+
def _list_outputs(self):
565+
566+
outputs = self._outputs().get()
567+
568+
outputs["out_file"] = self.inputs.out_file
569+
if self.inputs.mask is True:
570+
outputs["mask_file"] = os.path.abspath(self._gen_maskfilename())
571+
572+
return outputs
573+
574+
485575
if __name__ == '__main__':
486576
ab = AtlasBREX()
487577

macapype/pipelines/extract_brain.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import nipype.interfaces.fsl as fsl
99

10-
from ..nodes.extract_brain import AtlasBREX, HDBET
10+
from ..nodes.extract_brain import AtlasBREX, HDBET, Bet4Animal
1111

1212
from ..utils.utils_nodes import NodeParams, parse_key
1313

@@ -73,7 +73,30 @@ def create_extract_pipe(params_template, params={},
7373
extract_pipe.connect(inputnode, 'restore_T1',
7474
smooth, 'in_file')
7575

76-
if "hdbet" in params.keys():
76+
if "bet4animal" in params:
77+
bet4animal = NodeParams(
78+
Bet4Animal(),
79+
params=parse_key(params, "bet4animal"),
80+
name='bet4animal')
81+
82+
if "smooth" in params.keys():
83+
extract_pipe.connect(
84+
smooth, 'smoothed_file',
85+
bet4animal, 'in_file')
86+
else:
87+
88+
extract_pipe.connect(
89+
inputnode, 'restore_T1',
90+
bet4animal, 'in_file')
91+
92+
extract_pipe.connect(
93+
inputnode, ("indiv_params", parse_key, "bet4animal"),
94+
bet4animal, 'indiv_params')
95+
96+
# outputnode
97+
extract_pipe.connect(bet4animal, 'mask_file', outputnode, 'mask_file')
98+
99+
elif "hdbet" in params.keys():
77100
hdbet = NodeParams(HDBET(),
78101
params=parse_key(params, "hdbet"),
79102
name='hdbet')

macapype/utils/data_test_servers.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
"MBM_v3.0.1_6seg_stereoINT_largeFOV": "PREL3NDPrrcytPT",
4343

4444
"bma-1": "29qRZrnHnBxtCGB",
45-
"bma-1_0p2mm": "YoLAFawKMTi7FqR"
45+
"bma-1_0p2mm": "YoLAFawKMTi7FqR",
46+
47+
"MNI_Fortin_1mm": "24R6837rwH6PQSj",
48+
"MNI_Fortin_2mm": "fEAWFSyfGD37nH9"
49+
4650
},
4751
"cloud_format": "{}/public.php?service=files&t={}&download",
4852
"curl_cloud_format": "{}/public.php/dav/files/{}"

macapype/utils/templates.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@
9696
"template_wm": "wm.nii.gz",
9797
"template_csf": "csf.nii.gz"
9898
},
99+
"MNI_Fortin_1mm":
100+
{
101+
"template_head": "MNI152_T1_1mm.nii.gz",
102+
"template_brain": "MNI152_T1_1mm_Brain.nii.gz",
103+
"template_seg": "MNI152_T1_1mm_Brain_FAST_seg.nii.gz"
104+
},
105+
"MNI_Fortin_2mm":
106+
{
107+
"template_head": "MNI152_T1_2mm.nii.gz",
108+
"template_brain": "MNI152_T1_2mm_Brain.nii.gz",
109+
"template_seg": "MNI152_T1_2mm_Brain_FAST_seg.nii.gz"
110+
},
99111
"bma-1":
100112
{
101113
"template_head": "bma-1-mri.nii.gz",
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"general":
3+
{
4+
"template_name": "BaBa21-0"
5+
},
6+
"short_preparation_pipe":
7+
{
8+
"use_T2":{},
9+
"aladin_T2_on_T1":{},
10+
"crop_aladin_pipe":
11+
{
12+
"reg_T1_on_template":
13+
{
14+
"rig_only_flag":true
15+
},
16+
"reg_T1_on_template2":
17+
{
18+
"rig_only_flag":true
19+
}
20+
},
21+
"denoise":
22+
{
23+
},
24+
"N4debias":
25+
{
26+
"dimension": 3,
27+
"bspline_fitting_distance": 200,
28+
"n_iterations": [50, 50, 40, 30],
29+
"convergence_threshold": 0.00000001,
30+
"shrink_factor": 2,
31+
"args": "-r 0 --verbose 1"
32+
}
33+
},
34+
"extract_pipe":
35+
{
36+
"use_T2":{},
37+
38+
"bet4animal":
39+
{
40+
"f": 0.5,
41+
"label": 2,
42+
"robust": true
43+
}
44+
},
45+
"debias":
46+
{
47+
"s": 2
48+
},
49+
"brain_segment_pipe":
50+
{
51+
"use_T2": {},
52+
"reg":
53+
{
54+
"n": 2,
55+
"m": "ref",
56+
"dof": 12
57+
},
58+
"segment_atropos_pipe":
59+
{
60+
"use_priors": 0.0,
61+
"Atropos":
62+
{
63+
"dimension": 3
64+
},
65+
"tissue_dict":
66+
{
67+
"gm": 2,
68+
"wm": 3,
69+
"csf": 1
70+
}
71+
},
72+
"export_5tt_pipe":
73+
{
74+
},
75+
"IsoSurface_brain_pipe":
76+
{
77+
"merge_brain_tissues":
78+
{
79+
"keep_indexes": [1,2,3]
80+
}
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)