# Path: src/utils.py
# def splitext(s):
#     try :
#         ssplit = os.path.basename(s).split('.')
#         ext='.'+'.'.join(ssplit[1:])
#         basepath= re.sub(ext,'',s)
#         return [basepath, ext]
#     except TypeError :  
#         return s
# 
# def check_gz(in_file_fn) :
#     img, ext = splitext(in_file_fn)
#     if '.gz' in ext :
#         out_file_fn = tempfile.mkdtemp() + os.path.basename(img) + '.nii'
#         sif = img + '.sif'
#         if os.path.exists(sif) : 
#             shutil.copy(sif, '/tmp/'+os.path.basename(img)+'.sif'  )
#         gunzip(in_file_fn, out_file_fn) 
#         return out_file_fn
#     else :
#         return in_file_fn
# 
# def cmd(command):
#     try:
#         output = subprocess.check_output(command,stderr=subprocess.STDOUT, shell=True, universal_newlines=True)
#     except subprocess.CalledProcessError as exc:
#         print("Status : FAIL", exc.returncode, exc.output)
#         exit(1)
#     else:
#         print("Output: \n{}\n".format(output))


from nipype.interfaces.base import (TraitedSpec, File, traits, BaseInterface,  BaseInterfaceInputSpec, isdefined, CommandLineInputSpec, CommandLine)
from src.utils import splitext, check_gz, cmd
import ntpath
import os
        return outputs

    def _gen_output(self, basefile, _suffix):
        fname = ntpath.basename(basefile)
        fname_list = splitext(fname) # [0]= base filename; [1] =extension
        dname = os.getcwd() 
        return dname+ os.sep+fname_list[0] + _suffix + fname_list[1]

    def _parse_inputs(self, skip=None):
        if skip is None:
            skip = []
        if not isdefined(self.inputs.out_file):
            self.inputs.out_file = self._gen_output(self.inputs.in_file, self._suffix)

        return super(quantificationCommand, self)._parse_inputs(skip=skip)


class srcCommandWrapper(BaseInterface):
    _quantCommand=None

    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)

# Path: src/utils.py
# def splitext(s):
#     try :
#         ssplit = os.path.basename(s).split('.')
#         ext='.'+'.'.join(ssplit[1:])
#         basepath= re.sub(ext,'',s)
#         return [basepath, ext]
#     except TypeError :  
#         return s
# 
# def check_gz(in_file_fn) :
#     img, ext = splitext(in_file_fn)
#     if '.gz' in ext :
#         out_file_fn = tempfile.mkdtemp() + os.path.basename(img) + '.nii'
#         sif = img + '.sif'
#         if os.path.exists(sif) : 
#             shutil.copy(sif, '/tmp/'+os.path.basename(img)+'.sif'  )
#         gunzip(in_file_fn, out_file_fn) 
#         return out_file_fn
#     else :
#         return in_file_fn
# 
# def cmd(command):
#     try:
#         output = subprocess.check_output(command,stderr=subprocess.STDOUT, shell=True, universal_newlines=True)
#     except subprocess.CalledProcessError as exc:
#         print("Status : FAIL", exc.returncode, exc.output)
#         exit(1)
#     else:
#         print("Output: \n{}\n".format(output))


# Path: src/quant_methods/quantification_template.py
from nipype.interfaces.base import (TraitedSpec, File, traits, BaseInterface,  BaseInterfaceInputSpec, isdefined, CommandLineInputSpec, CommandLine)
from src.utils import splitext, check_gz, cmd
import ntpath
import os

        return outputs

    def _gen_output(self, basefile, _suffix):
        fname = ntpath.basename(basefile)
        fname_list = splitext(fname) # [0]= base filename; [1] =extension
        dname = os.getcwd() 
        return dname+ os.sep+fname_list[0] + _suffix + fname_list[1]

    def _parse_inputs(self, skip=None):
        if skip is None:
            skip = []
        if not isdefined(self.inputs.out_file):
            self.inputs.out_file = self._gen_output(self.inputs.in_file, self._suffix)

        return super(quantificationCommand, self)._parse_inputs(skip=skip)


class srcCommandWrapper(BaseInterface):
    _quantCommand=None

    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' :