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

Starting with IDP scripts

parent 919598ae
No related branches found
No related tags found
No related merge requests found
No preview for this file type
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
......@@ -26,6 +26,7 @@ from bip.pipelines.dMRI_fieldmap import dMRI_fieldmap
from bip.pipelines.fMRI_task import fMRI_task
from bip.pipelines.fMRI_rest import fMRI_rest
from bip.pipelines.dMRI_diff import dMRI_diff
from bip.pipelines.IDPs_gen import IDPs_gen
log = logging.getLogger('bip.main')
......@@ -343,6 +344,7 @@ def main():
pipe, targets = fMRI_task.add_to_pipeline(ctx, pipe, tree, targets)
pipe, targets = fMRI_rest.add_to_pipeline(ctx, pipe, tree, targets)
pipe, targets = dMRI_diff.add_to_pipeline(ctx, pipe, tree, targets)
pipe, targets = IDPs_gen.add_to_pipeline(ctx, pipe, tree, targets)
# The skip-missing flag deals with cases where the subject is missing
# the data of some modalities. For more details, check:
......
#!/usr/bin/env python
#
# IDP_subject_ID.py - Generating IDP file with the subject ID.
#
# Author: Fidel Alfaro Almagro <fidel.alfaroalmagro@ndcn.ox.ac.uk>
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
# Author: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk>
#
# pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915
#
import logging
from pipe_tree import In, Out, Ref
from bip.utils.log_utils import redirect_logging
log = logging.getLogger(__name__)
def run(ctx,
T1_orig: In,
IDP_subject_ID: Out,
logs_dir: Ref):
with redirect_logging('IDP_subject_ID', outdir=logs_dir):
with open(IDP_subject_ID, 'wt', encoding="utf-8") as f:
f.write(f'{ctx.subject}\n')
#!/usr/bin/env python
#
# IDP_subject_centre.py - Generating IDP file with the acquisition centre.
#
# Author: Fidel Alfaro Almagro <fidel.alfaroalmagro@ndcn.ox.ac.uk>
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
# Author: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk>
#
# pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915
#
import os
import json
import logging
from pipe_tree import In, Out, Ref
from bip.utils.log_utils import redirect_logging
log = logging.getLogger(__name__)
def run(ctx,
T1_orig: In,
T1_dcm_txt: In,
dMRI_dcm_txt: Ref,
rfMRI_dcm_txt: Ref,
SWI_dcm_txt: Ref,
T2_dcm_txt: Ref,
tfMRI_dcm_txt: Ref,
logs_dir: Ref,
IDP_subject_centre: Out):
line = ""
for file_name in [T1_dcm_txt, T2_dcm_txt, rfMRI_dcm_txt, SWI_dcm_txt,
dMRI_dcm_txt, tfMRI_dcm_txt]:
if os.path.exists(file_name):
with open(file_name, 'rt', encoding="utf-8") as f:
cont = f.readlines()
for x in cont:
if x.startswith("(0008, 0081) Institution Address"):
line = x.replace("(0008, 0081) Institution Address", "")
line = line.strip().replace("ST: ", "").strip()
line = line.replace("'","").replace(",","__").replace(" ","_")
break
if line != "":
break
if line != "":
# TODO: Allow users to change the file with the sites
with open(ctx.get_data("IDPs/sites_UKBB.json"), "r", encoding="utf-8") as f:
sites = json.load(f)
centre = sites[line]
with redirect_logging('IDP_subject_centre', outdir=logs_dir):
with open(IDP_subject_centre, 'wt', encoding="utf-8") as f:
f.write(f'{centre}\n')
#!/usr/bin/env python
#
# struct_T1.py - Pipeline with the T1w processing.
#
# Author: Fidel Alfaro Almagro <fidel.alfaroalmagro@ndcn.ox.ac.uk>
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
# Author: Michiel Cottaar <michiel.cottaar@ndcn.ox.ac.uk>
#
# pylint: disable=C0103,E0602,C0114,C0115,C0116,R0913,R0914,R0915
#
import logging
from bip.utils.log_utils import redirect_logging
from bip.pipelines.IDPs_gen import IDP_subject_ID
from bip.pipelines.IDPs_gen import IDP_subject_centre
log = logging.getLogger(__name__)
def add_to_pipeline(ctx, pipe, tree, targets):
logs_dir=tree.get('logs_dir')
subj = ctx.subject
with redirect_logging('pipe_IDPs_gen', outdir=logs_dir):
pipe(IDP_subject_ID.run,
submit=dict(jobtime=200, name="BIP_IDPs_subject_ID_" + subj),
kwargs={'ctx' : ctx})
targets.append('IDP_subject_ID')
pipe(IDP_subject_centre.run,
submit=dict(jobtime=200, name="BIP_IDP_subject_centre_" + subj),
kwargs={'ctx' : ctx})
targets.append('IDP_subject_centre')
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