Пример #1
0
    def _run_interface(self, runtime):
        transforms = []
        invert_transform_flags = []
        if isdefined(self.inputs.transform_1):
            transforms.append(self.inputs.transform_1)
            invert_transform_flags.append(self.inputs.invert_1)

        if isdefined(self.inputs.transform_2):
            transforms.append(self.inputs.transform_2)
            invert_transform_flags.append(self.inputs.invert_2)

        if isdefined(self.inputs.transform_3):
            transforms.append(self.inputs.transform_3)
            invert_transform_flags.append(self.inputs.invert_3)

        #output file
        split = splitext(os.path.basename(self.inputs.input_image))
        self.inputs.output_image = os.getcwd() + os.sep + split[0] + split[1]
        if '_space-' in self.inputs.output_image:
            self.inputs.output_image = re.sub(
                '_space-[A-z]*_', "_space-" + self.inputs.target_space + "_",
                self.inputs.output_image)

        #combine transformation files and output flags
        transforms_zip = zip(transforms, invert_transform_flags)
        transform_string = ' '.join([
            '-t [ ' + str(t) + ' , ' + str(int(f)) + ' ]'
            for t, f in transforms_zip if t != None
        ])
        cmdline = "antsApplyTransforms --float -v 1 -e 3 -d 3 -n " + self.inputs.interpolation + " -i " + self.inputs.input_image + " " + transform_string + " -r " + self.inputs.reference_image + " -o " + self.inputs.output_image

        cmd(cmdline)

        return runtime
Пример #2
0
    def _run_interface(self, runtime):
        #Get extension for input transformation files
        ext_1 = splitext(self.inputs.transform_1)[1]
        ext_2 = splitext(self.inputs.transform_2)[1]

        if ext_1 in ['.mat', '.txt'] and ext_2 in ['.mat', '.txt']:
            self.inputs.out_file = os.getcwd(
            ) + os.sep + 'composite_affine.mat'
        elif ext_1 == '.h5' or ext_2 == '.h5':
            self.inputs.out_file = os.getcwd() + os.sep + 'composite_warp.h5'
        cmd("CompositeTransformUtil --assemble " + ' '.join([
            self.inputs.out_file, self.inputs.transform_1,
            self.inputs.transform_2
        ]))

        return runtime
Пример #3
0
 def _gen_output(self):
     fname = ntpath.basename(self.inputs.pet_file)
     fname_list = splitext(fname) # [0]= base filename; [1] =extension
     dname = os.getcwd() 
     kind='vxl'
     if self.inputs.roi_based == True :
         kind = 'roi'
     return dname+ os.sep+fname_list[0] +'_quant-'+kind+'-'+ self.inputs.quant_method +'.nii.gz'
Пример #4
0
 def _create_output_file(self, fn, space):
     basefn = os.path.basename(fn)
     if not '_space-' in basefn:
         basefn_split = splitext(basefn)
         return basefn_split[0] + '_space-' + space + basefn_split[1]
     else:
         return '_'.join([
             f if not 'space-' in f else 'space-' + space
             for f in basefn.split('_')
         ])
Пример #5
0
def mnc2vol(niftifile):
    if not os.path.exists(niftifile):
        print('Warning: could not find file', niftifile)
        exit(1)

    datatype = nib.load(niftifile).get_data().dtype
    basename = os.getcwd() + os.sep + splitext(os.path.basename(niftifile))[0]
    rawfile = basename + '.raw'
    headerfile = basename + '.header'
    minc2volume.make_raw(niftifile, datatype, rawfile)
    minc2volume.make_header(niftifile, datatype, headerfile)
Пример #6
0
    def _gen_output(self, basefile):
        fname = ntpath.basename(basefile)
        fname_list = splitext(fname)  # [0]= base filename; [1] =extension
        dname = os.getcwd()
        suffix = self._suffix
        if suffix[0] != '_':
            suffix = '_' + suffix

        out_fn = dname + os.sep + fname_list[0] + suffix + fname_list[1]
        if '.gz' not in fname_list[1]:
            out_fn += '.gz'

        return out_fn
Пример #7
0
    def _run_interface(self, runtime):

        quantNode = self._quantCommand()
        quantNode.inputs = self.inputs
        init_command = quantNode.cmdline
        modified_command = []
        self.inputs.out_file = quantNode.inputs.out_file
        for f in init_command.split(' '):
            if os.path.exists(f):
                f = check_gz(f)
            elif f == quantNode.inputs.out_file and splitext(
                    f)[1] == '.nii.gz':
                f = splitext(f)[0] + '.nii'
                self.inputs.out_file = f
            modified_command.append(f)

        print(modified_command)
        command = ' '.join(modified_command)
        print(command)
        cmd(command)

        print("Out file", self.inputs.out_file)
        return runtime
Пример #8
0
    def _run_interface(self, runtime):
        if not isdefined(self.inputs.out_file):
            base = os.path.basename(self.inputs.in_file)
            split = splitext(base)
            self.inputs.out_file = os.getcwd(
            ) + os.sep + split[0] + self._suffix + split[1]
            #Load PET 3D volume

        img = nib.load(self.inputs.in_file)
        vol = gaussian_filter(img.get_data(), 1)
        vol[vol < threshold_otsu(vol[vol > 0])] = 0
        vol[vol > 0] = 1
        nib.Nifti1Image(vol, img.affine,
                        img.header).to_filename(self.inputs.out_file)
        return runtime
Пример #9
0
def main(filename, datatype):
    if not os.path.isfile(filename):
        console_error("File {} does not exist.".format(filename), 1)

    check_minc_tools_installed()

    basename = splitext(os.path.basename(filename))
    dirname = os.path.dirname(filename)
    headername = "{}/{}.header".format(dirname, basename)
    rawname = "{}/{}.raw".format(dirname, basename)

    console_log("Processing file: {}".format(filename))

    console_log("Creating header file: {}".format(headername))
    make_header(filename, datatype, headername)

    console_log("Creating raw data file: {}".format(rawname))
    make_raw(filename, datatype, rawname)
Пример #10
0
 def _gen_output(self, basefile):
     fname = ntpath.basename(basefile)
     fname_list = splitext(fname)  # [0]= base filename; [1] =extension
     dname = os.getcwd()
     return dname + os.sep + fname_list[0] + "_brain_mask" + fname_list[1]
Пример #11
0
 def _gen_output(self, in_file):
     ii = splitext(os.path.basename(in_file))[0]
     out_file = os.getcwd() + os.sep + ii + "_int.csv"
     return out_file