Skip to content

Commit

Permalink
adding more logging and validation of inputs and outputs within extra…
Browse files Browse the repository at this point in the history
…ct_b0_vol
  • Loading branch information
tokeefe committed Apr 25, 2024
1 parent 959e9d5 commit 6250050
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions dwiqc/tasks/prequal_EQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import json
from executors.models import Job


logger = logging.getLogger()

class Task(tasks.BaseTask):
def __init__(self, sub, ses, run, bids, outdir, container_dir=None, parent=None, tempdir=None, pipenv=None):
Expand Down Expand Up @@ -169,15 +169,37 @@ def parse_json(self, eddy_dir):
logging.info('successfully parsed json and wrote out results to eddy_metrics.json')

def extract_b0_vol(self):
os.chdir(f"{self._outdir}/PREPROCESSED")
extract_command = f"""singularity exec \
{self._fsl_sif} \
/APPS/fsl/bin/fslselectvols \
-i dwmri.nii.gz \
-o b0_volume \
--vols=0"""
proc1 = subprocess.Popen(extract_command, shell=True, stdout=subprocess.PIPE)
proc1.communicate()
dwmri = f'{self._outdir}/PREPROCESSED/dwmri.nii.gz'
logger.info(f'checking for input file "{dwmri}"')
if not os.path.exists(dwmri):
raise FileNotFoundError(dwmri)
logger.info(f'found input file "{dwmri}"')
bindings = os.environ.get('SINGULARITY_BIND', None)
logger.info(f'SINGULARITY_BIND environment variable is set to "{bindings}"')
preproc_dir = f'{self._outdir}/PREPROCESSED'
cmd = [
'singularity',
'exec',
'--pwd', preproc_dir,
self._fsl_sif,
'/APPS/fsl/bin/fslselectvols',
'-i', 'dwmri.nii.gz',
'-o', 'b0_volume',
'--vols=0'
]
cmdline = subprocess.list2cmdline(cmd)
logger.info(f'running {cmdline}')
proc = subprocess.Popen(cmdline, shell=True, stdout=subprocess.PIPE)
proc.communicate()
if proc.returncode > 0:
logger.critical(f'fslselectvols command failed')
raise subprocess.CalledProcessError(returncode=proc.returncode, cmd=cmd)
logging.info(f'fslselectvols exited with returncode={proc.returncode}')
b0vol = os.path.join(preproc_dir, 'b0_volume.nii.gz')
logging.info(f'checking for output file "{b0vol}"')
if not os.path.exists(b0vol):
raise FileNotFoundError(b0vol)
logger.info(f'found output file "{b0vol}"')

def bind_environmentals(self):

Expand Down

0 comments on commit 6250050

Please sign in to comment.