Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
scale = {"G": 1, "T": 10 ** 3, "M": 1e-3, "K": 1e-6, "B": 1e-9}
digits = "".join([c for c in value if c.isdigit()])
units = value[len(digits):] or "G"
return int(digits) * scale[units[0]]
def _drop_sub(value):
value = str(value)
return value.lstrip("sub-")
def _bids_filter(value):
from json import loads
if value and Path(value).exists():
return loads(Path(value).read_text())
verstr = f"MRIQC v{config.environment.version}"
currentv = Version(config.environment.version)
parser = ArgumentParser(
description=f"""\
MRIQC {config.environment.version}
Automated Quality Control and visual reports for Quality Assesment of structural \
(T1w, T2w) and functional MRI of the brain.
{config.DSA_MESSAGE}""",
formatter_class=ArgumentDefaultsHelpFormatter,
)
PathExists = partial(_path_exists, parser=parser)
PositiveInt = partial(_min_one, parser=parser)
# Arguments as specified by BIDS-Apps
# required, positional arguments
def init_mriqc_wf():
"""Create a multi-subject MRIQC workflow."""
from .. import config
workflow = Workflow(name="mriqc_wf")
workflow.base_dir = config.execution.work_dir
wf_list = []
for mod, filelist in config.workflow.inputs.items():
if mod == 'bold':
wf_list.append(fmri_qc_workflow())
else:
wf_list.append(anat_qc_workflow())
if not wf_list:
return None
workflow.add_nodes(wf_list)
return workflow
workflow.connect([
(drop_trs, st_corr, [('out_file', 'in_file')]),
(st_corr, deoblique_node, [('out_file', 'in_file')]),
(deoblique_node, gen_ref, [('out_file', 'in_file')]),
(deoblique_node, hmc, [('out_file', 'in_file')]),
])
elif config.workflow.correct_slice_timing:
workflow.connect([
(drop_trs, st_corr, [('out_file', 'in_file')]),
(st_corr, gen_ref, [('out_file', 'in_file')]),
(st_corr, hmc, [('out_file', 'in_file')]),
])
elif config.workflow.despike and config.workflow.deoblique:
workflow.connect([
(drop_trs, despike_node, [('out_file', 'in_file')]),
(despike_node, deoblique_node, [('out_file', 'in_file')]),
(deoblique_node, gen_ref, [('out_file', 'in_file')]),
(deoblique_node, hmc, [('out_file', 'in_file')]),
])
elif config.workflow.despike:
workflow.connect([
(drop_trs, despike_node, [('out_file', 'in_file')]),
(despike_node, gen_ref, [('out_file', 'in_file')]),
(despike_node, hmc, [('out_file', 'in_file')]),
])
.. workflow::
import os.path as op
from mriqc.workflows.functional import fmri_qc_workflow
from mriqc.testing import mock_config
with mock_config():
wf = fmri_qc_workflow()
"""
from niworkflows.interfaces.utils import SanitizeImage
workflow = pe.Workflow(name=name)
mem_gb = config.workflow.biggest_file_gb
dataset = config.workflow.inputs.get("bold", [])
config.loggers.workflow.info(f"""\
Building functional MRIQC workflow for files: {', '.join(dataset)}.""")
# Define workflow, inputs and outputs
# 0. Get data, put it in RAS orientation
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file']), name='inputnode')
inputnode.iterables = [('in_file', dataset)]
outputnode = pe.Node(niu.IdentityInterface(
fields=['qc', 'mosaic', 'out_group', 'out_dvars',
'out_fd']), name='outputnode')
non_steady_state_detector = pe.Node(nac.NonSteadyStateDetector(),
name="non_steady_state_detector")
def _run_interface(self, runtime):
from nipype.utils.filemanip import hash_infile
self._results["out_prov"] = {
"md5sum": hash_infile(self.inputs.in_file),
"version": config.environment.version,
"software": "mriqc",
"webapi_url": config.execution.webapi_url,
"webapi_port": config.execution.webapi_port,
"settings": {"testing": config.execution.debug, },
}
if self.inputs.modality in ("T1w", "T2w"):
air_msk_size = (
np.asanyarray(nb.load(self.inputs.air_msk).dataobj).astype(bool).sum()
)
rot_msk_size = (
np.asanyarray(nb.load(self.inputs.rot_msk).dataobj).astype(bool).sum()
)
self._results["out_prov"]["warnings"] = {
"small_air_mask": bool(air_msk_size < 5e5),
"large_rot_frame": bool(rot_msk_size > 500),
}
if self.inputs.modality == "bold":
'out_fd']), name='outputnode')
non_steady_state_detector = pe.Node(nac.NonSteadyStateDetector(),
name="non_steady_state_detector")
sanitize = pe.Node(SanitizeImage(), name="sanitize",
mem_gb=mem_gb * 4.0)
sanitize.inputs.max_32bit = config.execution.float32
# Workflow --------------------------------------------------------
# 1. HMC: head motion correct
hmcwf = hmc()
# Set HMC settings
hmcwf.inputs.inputnode.fd_radius = config.workflow.fd_radius
mean = pe.Node(afni.TStat( # 2. Compute mean fmri
options='-mean', outputtype='NIFTI_GZ'), name='mean',
mem_gb=mem_gb * 1.5)
skullstrip_epi = fmri_bmsk_workflow(use_bet=True)
# EPI to MNI registration
ema = epi_mni_align()
# Compute TSNR using nipype implementation
tsnr = pe.Node(nac.TSNR(), name='compute_tsnr', mem_gb=mem_gb * 2.5)
# 7. Compute IQMs
iqmswf = compute_iqms()
# Reports
repwf = individual_reports()
participant_label = set(config.execution.participant_label)
missing_subjects = participant_label - set(all_subjects)
if missing_subjects:
parser.error(
"One or more participant labels were not found in the BIDS directory: "
f"{', '.join(missing_subjects)}."
)
config.execution.participant_label = sorted(participant_label)
# Handle analysis_level
analysis_level = set(config.workflow.analysis_level)
if not config.execution.participant_label:
analysis_level.add("group")
config.workflow.analysis_level = list(analysis_level)
# List of files to be run
bids_filters = {
"participant_label": config.execution.participant_label,
"session": config.execution.session_id,
"run": config.execution.run_id,
"task": config.execution.task_id,
"bids_type": config.execution.modalities,
}
config.workflow.inputs = {
mod: files
for mod, files in collect_bids_data(
config.execution.layout, **bids_filters
).items()
if files
}
def build_workflow(config_file, retval):
"""Create the Nipype Workflow that supports the whole execution graph."""
from .. import config
from ..workflows.core import init_mriqc_wf
config.load(config_file)
retval["return_code"] = 1
retval["workflow"] = None
retval["workflow"] = init_mriqc_wf()
retval["return_code"] = int(retval["workflow"] is None)
return retval