def build(self): needDeps(self) fssubjdir = self.fs.output().dirname.dirname with TemporaryDirectory() as tmpdir, BRAINSTools.env(self.bthash): tmpoutdir = tmpdir / (self.caseid + '-fsindwi') dwi = tmpdir / 'dwi.nrrd' dwimask = tmpdir / 'dwimask.nrrd' fs = tmpdir / 'fs' t2 = tmpdir / 't2.nrrd' t1 = tmpdir / 't1.nrrd' t1mask = tmpdir / 't1mask.nrrd' t2mask = tmpdir / 't2mask.nrrd' fssubjdir.copy(fs) dwiconvert_py('-i', self.dwi.output(), '-o', dwi) convertImage(self.dwimask.output(), dwimask, self.bthash) convertImage(self.t2.output(), t2, self.bthash) convertImage(self.t1.output(), t1, self.bthash) convertImage(self.t2mask.output(), t2mask, self.bthash) convertImage(self.t1mask.output(), t1mask, self.bthash) script = local['pnlpipe_pipelines/pnlscripts/old/fs2dwi_T2.sh'] script['--fsdir', fs, '--dwi', dwi, '--dwimask', dwimask, '--t2', t2, '--t2mask', t2mask, '--t1', t1, '--t1mask', t1mask, '-o', tmpoutdir] & FG convertImage(tmpoutdir / 'wmparc-in-bse.nrrd', self.output(), self.bthash)
def build(self): needDeps(self) with BRAINSTools.env(self.bthash): from pnlscripts.util.scripts import epi_py epi_py('--force', '--dwi', self.dwi.output(), '--dwimask', self.dwimask.output(), '--t2', self.t2.output(), '--t2mask', self.t2mask.output(), '-o', self.output())
def build(self, db): needDeps(self, self.deps, db) with HCPPipelines.env( self.version_HCPPipelines), TemporaryDirectory() as tmpdir: preproc = local[HCPPipelines.get_path(self.version_HCPPipelines) / 'DiffusionPreprocessing/DiffPreprocPipeline.sh'] posPaths = [n.output() for n in self.posDwis] negPaths = [n.output() for n in self.negDwis] datadir = tmpdir / 'hcp/data' from os import getpid hcpdir = OUTDIR / self.caseid / 'hcp-{}'.format(getpid()) datadir = hcpdir / 'data' try: preproc['--path={}'.format(OUTDIR), '--subject={}'.format(self.caseid), '--PEdir={}'.format(self.peDir), '--posData=' + '@'.join(posPaths), '--negData=' + '@'.join(negPaths), '--echospacing={}'.format(self.echoSpacing), '--gdcoeffs=NONE', '--dwiname=hcp-{}'.format(getpid())] & FG except ProcessExecutionError as e: if not (datadir / 'data.nii.gz').exists(): print(e) log.error("HCP failed to make '{}'".format(datadir / 'data.nii.gz')) (OUTDIR / self.caseid / 'T1w').delete() sys.exit(1) (OUTDIR / self.caseid / 'T1w').delete() (datadir / 'data.nii.gz').move(self.output()) (datadir / 'bvals').move(self.output().with_suffix('.bval', depth=2)) (datadir / 'bvecs').move(self.output().with_suffix('.bvec', depth=2))
def build(self, db): needDeps(self, self.deps, db) measureTracts_py = local[ 'pnlpipe_pipelines/pnlscripts/measuretracts/measureTracts.py'] vtks = self.wmql.output().up() // '*.vtk' measureTracts_py['-f', '-c', 'caseid', 'algo', '-v', self.caseid, self.wmql.showCompressedDAG(), '-o', self.output(), '-i', vtks] & FG
def build(self, db): needDeps(self, self.deps, db) # make sure FREESURFER_HOME is set to right version pnlpipe_software.FreeSurfer.validate(self.version_FreeSurfer) from pnlscripts.util.scripts import fs_py fs_py['-i', self.t1.output(), '-m', self.t1mask.output(), '-f', '-o', self.output().dirname.dirname] & FG
def build(self, db): needDeps(self, self.deps, db) if self.output().up().exists(): self.output().up().delete() with tract_querier.env(self.tqhash): from pnlscripts.util.scripts import wmql_py wmql_py['-i', self.ukf.output(), '--fsindwi', self.fsindwi.output(), '-o', self.output().dirname] & FG
def build(self, db): needDeps(self, self.deps, db) fssubjdir = self.fs.output().dirname.dirname with TemporaryDirectory() as tmpdir, BRAINSTools.env(self.bthash): tmpoutdir = tmpdir / (self.caseid + '-fsindwi') tmpdwi = tmpdir / 'dwi.nrrd' tmpdwimask = tmpdir / 'dwimask.nrrd' dwiconvert_py('-i', self.dwi.output(), '-o', tmpdwi) convertImage(self.dwimask.output(), tmpdwimask, self.bthash) fs2dwi_py['-f', fssubjdir, '-t', tmpdwi, '-m', tmpdwimask, '-o', tmpoutdir, 'direct'] & FG local.path(tmpoutdir / 'wmparcInDwi1mm.nii.gz').copy(self.output())
def build(self): from plumbum.cmd import ImageMath needDeps(self) with TemporaryDirectory() as tmpdir, pnlpipe_software.BRAINSTools.env( self.hash_BRAINSTools): tmptxt = tmpdir / 'dice.txt' ImageMath[3, tmptxt, "DiceAndMinDistSum", self.maskManual.path(), self.mask.path()] & FG with open(tmptxt, 'r') as f: coeff = f.read().split(' ')[-1] with open(self.output(), 'w') as f: f.write(coeff)
def build(self, db): needDeps(self, self.deps, db) with TemporaryDirectory() as tmpdir, BRAINSTools.env(self.bthash): tmpdir = local.path(tmpdir) # antsRegistration can't handle a non-conventionally named file, so # we need to pass in a conventionally named one tmpt1 = tmpdir / ('t1' + ''.join(self.t1.output().suffixes)) from plumbum.cmd import ConvertBetweenFileFormats ConvertBetweenFileFormats[self.t1.output(), tmpt1] & FG trainingCsv = trainingDataT1AHCC.get_path( self.trainingDataT1AHCC) / 'trainingDataT1AHCC-hdr.csv' atlas_py['csv', '--fusion', 'avg', '-t', tmpt1, '-o', tmpdir, trainingCsv] & FG (tmpdir / 'mask.nrrd').copy(self.output())
def build(self): needDeps(self) with TemporaryDirectory() as tmpdir, local.cwd( tmpdir), pnlpipe_software.mrtrix3.env(self.hash_mrtrix3): from plumbum.cmd import maskfilter slicerDir = pnlpipe_software.Slicer.get_path( self.version_Slicer).dirname Slicer = local[slicerDir / 'Slicer'] Slicer['--launch', slicerDir / 'DiffusionWeightedVolumeMasking', self.dwi.path(), 'b0.nrrd', 'otsumask.nrrd', '--baselineBValueThreshold', '1000', '--removeislands'] & FG Slicer['--launch', 'ResampleScalarVolume', 'otsumask.nrrd', 'otsumask.nii'] & FG maskfilter['-scale', 2, 'otsumask.nii', 'clean', self.output(), '-force'] & FG
def build(self, db): needDeps(self, self.deps, db) with BRAINSTools.env(self.bthash), TemporaryDirectory() as tmpdir: from pnlscripts.util.scripts import makeRigidMask_py moving = tmpdir / 'moving.nrrd' movingmask = tmpdir / 'movingmask.nrrd' fixed = tmpdir / 'fixed.nrrd' out = tmpdir / 'fixedmask.nrrd' convertImage(self.movingStrct.output(), moving, self.bthash) convertImage(self.movingStrctMask.output(), movingmask, self.bthash) convertImage(self.fixedStrct.output(), fixed, self.bthash) makeRigidMask_py('-i', moving, '--labelmap', movingmask, '--target', fixed, '-o', out) out.move(self.output())
def build(self): needDeps(self) with BRAINSTools.env(self.bthash), TemporaryDirectory() as tmpdir: tmpdir = local.path(tmpdir) tmpdwi = tmpdir / 'dwi.nrrd' tmpdwimask = tmpdir / 'dwimask.nrrd' dwiconvert_py('-i', self.dwi.output(), '-o', tmpdwi) convertImage(self.dwimask.output(), tmpdwimask, self.bthash) params = [ '--dwiFile', tmpdwi, '--maskFile', tmpdwimask, '--seedsFile', tmpdwimask, '--recordTensors', '--tracts', self.output() ] + defaultUkfParams ukfpath = UKFTractography.get_path(self.ukfhash) log.info(' Found UKF at {}'.format(ukfpath)) ukfbin = local[ukfpath] ukfbin(*params)
def build(self, db): needDeps(self, self.deps, db) with BRAINSTools.env(self.bthash), TemporaryDirectory() as tmpdir: nrrd = tmpdir / 'strct.nrrd' convertImage(self.strct.output(), nrrd, self.bthash) alignAndCenter_py['-i', nrrd, '-o', self.output()] & FG
def build(self): needDeps(self) with BRAINSTools.env(self.bthash), TemporaryDirectory() as tmpdir: bet_py('--force', '-f', self.threshold, '-i', self.dwi.output(), '-o', self.output())
def build(self, db): needDeps(self, self.deps, db) with BRAINSTools.env(self.bthash), TemporaryDirectory() as tmpdir: tmpdwi = tmpdir / (self.caseid + '-dwi.nrrd') dwiconvert_py['-f', '-i', self.dwi.output(), '-o', tmpdwi] & FG alignAndCenter_py['-i', tmpdwi, '-o', self.output()] & FG
def build(self, db): needDeps(self, self.deps, db) with BRAINSTools.env(self.bthash): eddy_py['-i', self.dwi.output(), '-o', self.output(), '--force'] & FG