Skip to content
Snippets Groups Projects
Commit 8a656063 authored by Fidel Alfaro Almagro's avatar Fidel Alfaro Almagro :speech_balloon:
Browse files

Adding BIANCA processing

parent 4e34a95e
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File added
File added
...@@ -34,8 +34,8 @@ def run(ctx, ...@@ -34,8 +34,8 @@ def run(ctx,
env = dict(os.environ, SUBJECTS_DIR=os.getcwd() + "/" + ctx.subject) env = dict(os.environ, SUBJECTS_DIR=os.getcwd() + "/" + ctx.subject)
T1_path = subjects_dir + "/" + T1_unbiased T1_path = os.getcwd() + "/" + T1_unbiased
T2_path = subjects_dir + "/" + T2_FLAIR_unbiased T2_path = os.getcwd() + "/" + T2_FLAIR_unbiased
cmd = 'recon-all -all -s FreeSurfer -i ' + T1_path cmd = 'recon-all -all -s FreeSurfer -i ' + T1_path
......
#!/usr/bin/env python
#
# T2_FLAIR_bianca.py - Sub-pipeline with FSL's BIANCA processing of T2 FLAIR.
#
# Author: Gaurav Bhalerao <gaurav.bhalerao@psych.ox.ac.uk>
# Author: Fidel Alfaro Almagro <fidel.alfaroalmagro@ndcn.ox.ac.uk>
#
# pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915
# pylint: disable=W0613,C0301
#
import logging
from shutil import copyfile
from pipe_tree import In, Out, Ref
from fsl import wrappers
from bip.utils.log_utils import redirect_logging
log = logging.getLogger(__name__)
def run(ctx,
T1_unbiased: In,
T2_FLAIR_unbiased: In,
T1_to_MNI_warp_coef_inv: In,
T1_to_MNI_linear_mat: In,
T1_fast_pve_0: In,
T1_unbiased_brain: In,
T1_brain_mask: In,
logs_dir: Ref,
T1_dir: Ref,
T2_FLAIR_dir: Ref,
T2_FLAIR_bianca_lesion_dir: Ref,
T1_transforms_dir: Ref,
T1_unbiased_brain_mask: Out,
T1_unbiased_bianca_mask: Out,
T1_unbiased_ventmask: Out,
bianca_T1_unbiased_brain_mask: Out,
bianca_T1_unbiased_bianca_mask: Out,
bianca_T1_unbiased_ventmask: Out,
T2_FLAIR_bianca_conf_file: Out,
T2_FLAIR_bianca_mask: Out,
T2_FLAIR_bianca_final_mask: Out,
T2_FLAIR_bianca_deepwm_map: Out,
T2_FLAIR_bianca_perivent_map: Out,
T2_FLAIR_bianca_tot_pvent_deep_volume: Out,
T2_FLAIR_bianca_volume: Out):
with redirect_logging('T2_FLAIR_bianca', outdir=logs_dir):
# Create bianca mask
wrappers.make_bianca_mask(T1_unbiased, T1_fast_pve_0,
T1_to_MNI_warp_coef_inv, keep_files=False)
copyfile(src=T1_unbiased_brain_mask,dst=bianca_T1_unbiased_brain_mask)
copyfile(src=T1_unbiased_bianca_mask,dst=bianca_T1_unbiased_bianca_mask)
copyfile(src=T1_unbiased_ventmask,dst=bianca_T1_unbiased_ventmask)
# Create masterfile for bianca
filenames =[T1_unbiased_brain, T2_FLAIR_unbiased, T1_to_MNI_linear_mat]
with open(T2_FLAIR_bianca_conf_file, 'w', encoding="utf-8") as f:
for j in filenames:
f.write(j+" ")
# Run bianca
bianca_class_data = ctx.get_data("bianca/bianca_class_data")
wrappers.bianca(singlefile = T2_FLAIR_bianca_conf_file,
querysubjectnum = 1, brainmaskfeaturenum = 1,
loadclassifierdata = bianca_class_data,
matfeaturenum = 3, featuresubset = "1,2",
o = T2_FLAIR_bianca_mask)
# Multiply the lesions mask (bianca_mask) by the "unbiased_bianca_mask"
wrappers.fslmaths(T2_FLAIR_bianca_mask).mul(T1_brain_mask).thr(0.8).bin().run(T2_FLAIR_bianca_final_mask)
# Calculate total WMH (volume of the final mask),
# periventricular WMH & deep WMH - 10mm Criteria
wrappers.bianca_perivent_deep(wmh_map = T2_FLAIR_bianca_final_mask,
vent_mask = bianca_T1_unbiased_ventmask,
minclustersize = 0,
outputdir = T2_FLAIR_bianca_lesion_dir,
do_stats = 2)
vals = wrappers.fslstats(T2_FLAIR_bianca_final_mask).V.run()[0]
with open(T2_FLAIR_bianca_volume, 'wt', encoding="utf-8") as f:
f.write(str(vals) + "\n")
...@@ -13,6 +13,7 @@ import logging ...@@ -13,6 +13,7 @@ import logging
from bip.utils.log_utils import redirect_logging from bip.utils.log_utils import redirect_logging
from bip.pipelines.struct_T2_FLAIR import T2_FLAIR_gdc, T2_FLAIR_brain_extract from bip.pipelines.struct_T2_FLAIR import T2_FLAIR_gdc, T2_FLAIR_brain_extract
from bip.pipelines.struct_T2_FLAIR import T2_FLAIR_defacing, T2_FLAIR_apply_bfc from bip.pipelines.struct_T2_FLAIR import T2_FLAIR_defacing, T2_FLAIR_apply_bfc
from bip.pipelines.struct_T2_FLAIR import T2_FLAIR_bianca
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -39,5 +40,10 @@ def add_to_pipeline(ctx, pipe, tree, targets): ...@@ -39,5 +40,10 @@ def add_to_pipeline(ctx, pipe, tree, targets):
submit=dict(jobtime=200, name="BIP_T2_FLAIR_apply_bfc_" + subj), submit=dict(jobtime=200, name="BIP_T2_FLAIR_apply_bfc_" + subj),
kwargs={'ctx' : ctx}) kwargs={'ctx' : ctx})
targets.append('T2_FLAIR_unbiased_brain') targets.append('T2_FLAIR_unbiased_brain')
pipe(T2_FLAIR_bianca.run,
submit=dict(jobtime=200, name="BIP_T2_FLAIR_bianca_" + subj),
kwargs={'ctx' : ctx})
targets.append('T2_FLAIR_bianca_volume')
return pipe, targets return pipe, targets
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment