예제 #1
0
   def write_uber_command(self):
      if show_func_seq: print('=== R ===')  # rcr - not called

      pdir = self.ttobj.cvars.val('proc_dir')
      if os.path.isdir(pdir):
         sstr = self.make_uber_command()
         UTIL.write_text_to_file('%s/.orig.cmd.utt' % pdir, sstr)
예제 #2
0
   def write_script(self, fname=''):
      """write processing script to a file (in the proc_dir)
         - if fname is set, use it, else generate
         - set rvars.file_proc and output_proc
      """

      if not self.script:
         print('** no script to write out')
         return 1
      if fname: name = fname
      else: name = 'script.ttest'

      # store (intended) names for calling tool to execute with
      self.rvars.file_proc = name # store which file we have written to
      self.rvars.output_proc = 'output.%s' % name # file for command output

      if self.cvars.verb > 0: print('++ writing script to %s' % name)

      # if requested, make an original copy
      self.LV.retdir = SUBJ.goto_proc_dir(self.cvars.proc_dir)

      if self.cvars.copy_scripts == 'yes': # make an orig copy
         UTIL.write_text_to_file('.orig.%s'%name, self.script, exe=1)
      rv = UTIL.write_text_to_file(name, self.script, exe=1)

      self.LV.retdir = SUBJ.ret_from_proc_dir(self.LV.retdir)
         
      return rv
예제 #3
0
    def make_decon_script_old(self):
        """OLD METHOD: create the deconvolution (3dTfitter) script"""

        cmd  = '# ------------------------------------------------------\n'  \
               '# perform neuro deconvolution via 3dTfitter\n\n'

        cmd += "# create response kernel\n"                             \
               "waver -%s -peak 1 -dt %s -inline 1@1 > %s\n\n" %        \
                (self.kernel, self.tr, self.kfile)

        if self.aname.type == '1D': prefix = 'detrend.1D'
        else: prefix = 'detrend%s' % self.aname.view

        polort = UTIL.get_default_polort(self.tr, self.reps)
        cmd += '# detrend the input\n'                          \
               '3dDetrend -polort %d -prefix %s %s\n\n' %       \
                (polort,prefix,self.infiles[0])

        if self.maskset: mask = '          -mask %s \\\n' % self.maskset
        else: mask = ''

        if self.aname.type == '1D':
            cmd += '# transpose the detrended dataset\n'        \
                   '1dtranspose detrend.1D > detrend_tr.1D\n\n'
            dname = 'detrend_tr.1D'
        else:
            dname = 'detrend%s' % self.aname.view

        c2  = '3dTfitter -lsqfit -RHS %s \\\n'           \
              '%s'                                       \
              '          -FALTUNG %s %s \\\n'            \
              '          01 0.0\n\n' % (dname,mask,self.kfile,self.prefix)

        cmd += UTIL.add_line_wrappers(c2)
        return UTIL.write_text_to_file(self.script, cmd, exe=1)
예제 #4
0
3dBrickStat -mask $mask -percentile $bot $step 100 -non-zero \\
            $pre.abs+tlrc > $pre.abs.1D

# have percentile p-values, remove unwanted percentile rankings
1dcat $pre.abs.1D'[1..$(2)]' > $pre.at.1D

# transpose and convert t to p
1deval -a $pre.at.1D\\' -expr "fitt_t2p(a,$dof)" > $pre.p.1D

# convert p to q    (** note: the minimum is not applied, we do not want it)
1deval -a $pre.p.1D -expr "a*$nv/($nv-t)" > $pre.q.1D

# put both together in output file
1dcat $pre.p.1D $pre.q.1D > $output


# ----------------------------------------
# nuke temporary files (comment out to keep)
rm -f $pre.*

"""

ss += static_script

# and write output
U.write_text_to_file(outfile, ss)
try:
    os.chmod(outfile, 0o755)
except OSError as e:
    print(e)
예제 #5
0
 def write_uber_command(self):
     pdir = self.atest.cvars.val('proc_dir')
     if os.path.isdir(pdir):
         sstr = self.make_uber_command()
         UTIL.write_text_to_file('%s/.orig.cmd.uat' % pdir, sstr)
예제 #6
0
    def make_decon_script(self):
        """create the deconvolution (3dTfitter) script"""

        nups = '%02d' % self.tr_nup
        trup = self.tr / self.tr_nup
        penalty = '012'
        kernel = self.kernel
        kfile = self.kfile

        # todo: include run lengths

        # maybe call the 3D version
        if self.aname.type != '1D': return self.make_decon_script_3d()

        cmd  = '# ------------------------------------------------------\n'  \
               '# perform neuro deconvolution via 3dTfitter\n\n'

        cmd += '# make and copy files into output directory\n'          \
               'set outdir = %s\n'                                      \
               'if ( ! -d $outdir ) mkdir $outdir\n\n' % self.outdir

        # get a list of (hopefully shortened) file labels
        llist = UTIL.list_minus_glob_form(self.infiles)
        llen = len(self.infiles)
        fix = 0
        if len(llist) != llen: fix = 1
        else:
            if llist[0] == self.infiles[0]: fix = 1
        if fix: llist = ['%02d.ts' % (ind + 1) for ind in range(llen)]
        else:
            llist = ['%02d.%s' % (ind + 1, llist[ind]) for ind in range(llen)]

        # when copying file in, use 1dtranspose if they are horizontal
        adata = LD.AfniData(self.infiles[0], verb=self.verb)
        if not adata: return 1
        # rcr - in progress?  unused: adata, nt, transp
        if adata.nrows == 1:
            nt = adata.ncols * self.tr_nup
            trstr = '(no transpose on read)'
            trchr = ''
        else:
            nt = adata.nrows * self.tr_nup
            transp = 1
            trstr = '(transpose on read)'
            trchr = '\\\''

        cmd += 'set files = ( %s )\n'           \
               'set labels = ( %s )\n\n'        \
               'cp -pv $files $outdir\n'        \
               'cd $outdir\n\n'                 \
               % (' '.join(self.infiles), ' '.join(llist))

        if self.kfile_in: kfile = self.kfile_in
        else:
            # generate a response kernel using 3dDeconvolve
            if kernel == 'GAM': ntk = int(12 / trup + 0.5)
            elif kernel == 'BLOCK': ntk = int(15 / trup + 0.5)
            else:
                print('** only GAM/BLOCK basis functions are allowed now')
                return 1

            if kernel == 'BLOCK': kernel = 'BLOCK(0.1,1)'
            tmpc = '# create response kernel\n'                      \
                   '3dDeconvolve -nodata %d %g -polort -1 \\\n'      \
                   '   -num_stimts 1 -stim_times 1 "1D:0" "%s" \\\n' \
                   '   -x1D %s -x1D_stop\n\n' % (ntk, trup, kernel, kfile)
            cmd += UTIL.add_line_wrappers(tmpc)

        pind = 0
        cmd += '# process each input file\n'                      \
               'foreach findex ( `count -digits 2 1 $#files` )\n' \
               '   # no zero-padding in shell index\n'            \
               '   set ival   = `ccalc -i $findex`\n'             \
               '   set infile = $files[$ival]:t\n'                \
               '   set label  = $labels[$ival]\n\n'               \

        polort = UTIL.get_default_polort(self.tr, self.reps)
        olab = 'p%02d.det.$label.1D' % pind
        cmd += '   # detrend the input %s\n'                      \
               '   3dDetrend -polort %d -prefix %s $infile%s\n\n' \
               % (trstr, polort, olab, trchr)

        pind += 1
        ilab = olab
        olab = 'p%02d.det.tr.$label.1D' % pind
        cmd += '   # transpose the detrended dataset\n'        \
               '   1dtranspose %s > %s\n\n' % (ilab, olab)

        pind += 1
        ilab = olab
        olab = 'p%02d.up%s.$label.1D' % (pind, nups)
        cmd += '   # upsample by factor of %d\n'                \
               '   1dUpsample %d %s > %s\n\n'                   \
               % (self.tr_nup, self.tr_nup, ilab, olab)

        sfile_up = olab  # save original detrended upsample label

        pind += 1
        ilab = olab
        olab = 'p%02d.neuro.up%s.$label.1D' % (pind, nups)
        tmpc = '   3dTfitter -RHS %s \\\n'              \
              '             -FALTUNG %s %s \\\n'        \
              '             012 -2 -l2lasso -6\n\n' % (ilab,kfile,olab)
        cmd += UTIL.add_line_wrappers(tmpc)

        pind += 1
        ilab = olab
        olab = 'p%02d.neuro.up%s.tr.$label.1D' % (pind, nups)
        cmd += '   # transpose the neuro signal\n'      \
               '   1dtranspose %s > %s\n\n' % (ilab, olab)

        pind += 1
        ilab = olab
        olab = 'p%02d.reconv.up%s.tr.$label.1D' % (pind, nups)
        cmd += '   # reconvolve the neuro signal to compare with orig\n'\
               '   set nt = `cat %s | wc -l`\n'                         \
               '   waver -FILE %g %s -input %s \\\n'                \
               '         -numout $nt > %s\n\n'                          \
               % (ilab, trup, kfile, ilab, olab)

        rfile_up = olab  # save reconvolved label

        cmd += 'end\n\n\n'

        cmd += 'echo "compare upsample input to reconvolved result via:"\n' \
               'echo "set label = %s"\n'                                    \
               'echo "1dplot -one %s %s"\n\n'                                \
               % (llist[0], sfile_up, rfile_up)

        return UTIL.write_text_to_file(self.script, cmd, exe=1)