Skip to content

Commit

Permalink
Use QI mask instead of BET
Browse files Browse the repository at this point in the history
  • Loading branch information
spinicist committed Nov 29, 2023
1 parent f8cff8b commit 8ddeaec
Showing 1 changed file with 57 additions and 59 deletions.
116 changes: 57 additions & 59 deletions Python/qipype/workflows/mpm.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,63 @@
import numpy as np
from nipype import Workflow, Node, MapNode, IdentityInterface
from nipype.interfaces.fsl import maths, BET, MCFLIRT, ExtractROI, FLIRT, Merge, ApplyXFM, ImageMaths, BinaryMaths, ConvertXFM
from nipype.interfaces.fsl import FLIRT, Merge, ApplyXFM, ImageMaths
import nipype.interfaces.utility as util
from qipype.fitting import MPMR2s, MTSat
from qipype.commands import B1Minus
from qipype.fsl import ApplyXfm4D
from qipype.utils import Select
from qipype.utils import Select, Mask

def init_mpm_wf(me_params, mtsat_params):
inputnode = Node(IdentityInterface(fields=['PDw_file', 'T1w_file', 'MTw_file', 'B1_map']),
name='inputnode')
outputnode = Node(IdentityInterface(fields=['PD_map', 'R1_map', 'R2s_map', 'mtsat_map', 'brain_mask']),
name='outputnode')

wf = Workflow(name='Multi-Parametric-Mapping')

mask = Node(Mask(vol=0), name='mask')
wf.connect([(inputnode, mask, [('PDw_file', 'in_file')])])

pd0 = Node(Select(volumes=[0, ], out_file='pd0.nii.gz'), name='pd0')
t10 = Node(Select(volumes=[0, ], out_file='t10.nii.gz'), name='t10')
mt0 = Node(Select(volumes=[0, ], out_file='mt0.nii.gz'), name='mt0')
wf.connect([(inputnode, pd0, [('PDw_file', 'in_file')]),
(inputnode, t10, [('T1w_file', 'in_file')]),
(inputnode, mt0, [('MTw_file', 'in_file')])])

t1_reg = Node(FLIRT(uses_qform=True, cost='mutualinfo'), name='t1_reg')
mt_reg = Node(FLIRT(uses_qform=True, cost='mutualinfo'), name='mt_reg')
t1_apply = Node(ApplyXfm4D(single_matrix=True), name='t1_apply')
mt_apply = Node(ApplyXfm4D(single_matrix=True), name='mt_apply')
wf.connect([(t10, t1_reg, [('out_file', 'in_file')]),
(pd0, t1_reg, [('out_file', 'reference')]),
(inputnode, t1_apply, [('T1w_file', 'in_file')]),
(pd0, t1_apply, [('out_file', 'ref_vol')]),
(t1_reg, t1_apply, [('out_matrix_file', 'trans_file')]),
(mt0, mt_reg, [('out_file', 'in_file')]),
(pd0, mt_reg, [('out_file', 'reference')]),
(inputnode, mt_apply, [('MTw_file', 'in_file')]),
(pd0, mt_apply, [('out_file', 'ref_vol')]),
(mt_reg, mt_apply, [('out_matrix_file', 'trans_file')])])

mpm = Node(MPMR2s(sequence=me_params, verbose=True), name='MPM_R2s')
mtsat = Node(MTSat(sequence=mtsat_params, verbose=True), name='MPM_MTSat')

wf.connect([(inputnode, mpm, [('PDw_file', 'PDw_file')]),
(t1_apply, mpm, [('out_file', 'T1w_file')]),
(mt_apply, mpm, [('out_file', 'MTw_file')]),
(mask, mpm, [('out_file', 'mask_file')]),
(mpm, mtsat, [('S0_PDw_map', 'PDw_file'),
('S0_T1w_map', 'T1w_file'),
('S0_MTw_map', 'MTw_file')]),
(inputnode, mtsat, [('B1_map', 'B1_map')]),
(mask, mtsat, [('out_file', 'mask_file')]),
(mpm, outputnode, [('R2s_map', 'R2s_map')]),
(mtsat, outputnode, [('PD_map', 'PD_map'),
('R1_map', 'R1_map'),
('delta_map', 'mtsat_map')]),
(mask, outputnode, [('out_file', 'brain_mask')])])
return wf

def init_mpm_b1_wf(me_params, mtsat_params):
inputnode = Node(IdentityInterface(fields=['PDw_file', 'T1w_file', 'MTw_file',
Expand All @@ -18,8 +69,8 @@ def init_mpm_b1_wf(me_params, mtsat_params):

wf = Workflow(name='Multi-Parametric-Mapping')

bet = Node(BET(mask=True, no_output=True), name='brain_mask')
wf.connect([(inputnode, bet, [('T1w_file', 'in_file')])])
mask = Node(Mask(vol=0), name='mask')
wf.connect([(inputnode, mask, [('PDw_file', 'in_file')])])

PD_B1minus = Node(B1Minus(), name='PD_B1minus')
t1_B1minus = Node(B1Minus(), name='t1_B1minus')
Expand Down Expand Up @@ -82,67 +133,14 @@ def init_mpm_b1_wf(me_params, mtsat_params):
wf.connect([(pd_cal, mpm, [('out_file', 'PDw_file')]),
(t1_apply, mpm, [('out_file', 'T1w_file')]),
(mt_apply, mpm, [('out_file', 'MTw_file')]),
(bet, mpm, [('mask_file', 'mask_file')]),
(mask, mpm, [('out_file', 'mask_file')]),
(mpm, mtsat, [('S0_PDw_map', 'PDw_file'),
('S0_T1w_map', 'T1w_file'),
('S0_MTw_map', 'MTw_file')]),
(inputnode, mtsat, [('B1_map', 'B1_map')]),
(bet, mtsat, [('mask_file', 'mask_file')]),
(mask, mtsat, [('out_file', 'mask_file')]),
(mpm, outputnode, [('R2s_map', 'R2s_map')]),
(mtsat, outputnode, [('PD_map', 'PD_map'),
('R1_map', 'R1_map'),
('delta_map', 'mtsat_map')])])
return wf


def init_mpm_wf(me_params, mtsat_params):
inputnode = Node(IdentityInterface(fields=['PDw_file', 'T1w_file', 'MTw_file', 'B1_map']),
name='inputnode')
outputnode = Node(IdentityInterface(fields=['PD_map', 'R1_map', 'R2s_map', 'mtsat_map', 'brain_mask']),
name='outputnode')

wf = Workflow(name='Multi-Parametric-Mapping')

bet = Node(BET(mask=True, no_output=True), name='brain_mask')
wf.connect([(inputnode, bet, [('T1w_file', 'in_file')])])

pd0 = Node(Select(volumes=[0, ], out_file='pd0.nii.gz'), name='pd0')
t10 = Node(Select(volumes=[0, ], out_file='t10.nii.gz'), name='t10')
mt0 = Node(Select(volumes=[0, ], out_file='mt0.nii.gz'), name='mt0')
wf.connect([(inputnode, pd0, [('PDw_file', 'in_file')]),
(inputnode, t10, [('T1w_file', 'in_file')]),
(inputnode, mt0, [('MTw_file', 'in_file')])])

t1_reg = Node(FLIRT(uses_qform=True, cost='mutualinfo'), name='t1_reg')
mt_reg = Node(FLIRT(uses_qform=True, cost='mutualinfo'), name='mt_reg')
t1_apply = Node(ApplyXfm4D(single_matrix=True), name='t1_apply')
mt_apply = Node(ApplyXfm4D(single_matrix=True), name='mt_apply')
wf.connect([(t10, t1_reg, [('out_file', 'in_file')]),
(pd0, t1_reg, [('out_file', 'reference')]),
(inputnode, t1_apply, [('T1w_file', 'in_file')]),
(pd0, t1_apply, [('out_file', 'ref_vol')]),
(t1_reg, t1_apply, [('out_matrix_file', 'trans_file')]),
(mt0, mt_reg, [('out_file', 'in_file')]),
(pd0, mt_reg, [('out_file', 'reference')]),
(inputnode, mt_apply, [('MTw_file', 'in_file')]),
(pd0, mt_apply, [('out_file', 'ref_vol')]),
(mt_reg, mt_apply, [('out_matrix_file', 'trans_file')])])

mpm = Node(MPMR2s(sequence=me_params, verbose=True), name='MPM_R2s')
mtsat = Node(MTSat(sequence=mtsat_params, verbose=True), name='MPM_MTSat')

wf.connect([(inputnode, mpm, [('PDw_file', 'PDw_file')]),
(t1_apply, mpm, [('out_file', 'T1w_file')]),
(mt_apply, mpm, [('out_file', 'MTw_file')]),
(bet, mpm, [('mask_file', 'mask_file')]),
(mpm, mtsat, [('S0_PDw_map', 'PDw_file'),
('S0_T1w_map', 'T1w_file'),
('S0_MTw_map', 'MTw_file')]),
(inputnode, mtsat, [('B1_map', 'B1_map')]),
(bet, mtsat, [('mask_file', 'mask_file')]),
(mpm, outputnode, [('R2s_map', 'R2s_map')]),
(mtsat, outputnode, [('PD_map', 'PD_map'),
('R1_map', 'R1_map'),
('delta_map', 'mtsat_map')]),
(bet, outputnode, [('mask_file', 'brain_mask')])])
return wf

0 comments on commit 8ddeaec

Please sign in to comment.