def execute(self): if not self.ready_for_action(): return 1 if self.verb > 1: print('-- make %s command with %d set(s) of dsets of length(s): %s' \ % (self.command, len(self.dsets), ', '.join([str(len(dlist)) for dlist in self.dsets]) )) # might deal with subject IDs and attributes later for ind, dlist in enumerate(self.dsets): slist = SUBJ.SubjectList(dset_l=dlist, verb=self.verb) if slist.status: return 1 if slist.set_ids_from_dsets(prefix=self.subj_prefix, suffix=self.subj_suffix, dpre=self.dent_pre): print('** cannot set subject IDs from datasets') return 1 self.slist.append(slist) if self.verb > 2: slist.show("slist %d" % ind) cmd = None if self.command == '3dMEMA': cmd = self.get_mema_command() elif self.command == '3dttest++': cmd = self.get_ttpp_command() elif self.command == '3dANOVA2': cmd = self.get_anova2_command() elif self.command == '3dANOVA3': cmd = self.get_anova3_command() elif self.command: cmd = self.get_generic_command() else: print('** command not implemented: %s' % self.command) # bail on failure, else wrap command if cmd == None: print('** failed making %s command' % self.command) return 1 cmd = UTIL.add_line_wrappers(cmd) # either write to file or print if self.write_script: if UTIL.write_text_to_file(self.write_script, cmd): print("** failed to write command to file '%s'" % self.write_script) return 1 if self.verb > 0: print('++ command written to file %s' % self.write_script) else: print(cmd)
def make_align_opts_str(self): """any align options, one per line""" # keep comment separate to get indent length cmnt = '# all other align_epi_anat.py options\n' \ cstr = 'set align_opts = ( ' clen = len(cstr) istr = ' ' * clen # put one option on first line cstr += '%s \\\n' % '-tshift off' # ---------- here is the main option application --------- # then add each option offset by initial indentation cstr += '%s%s \\\n' % (istr, '-volreg off') if self.uvars.giant_move == 'yes': cstr += '%s%s \\\n' % (istr, '-giant_move') if self.uvars.add_edge == 'yes': if len(self.uvars.cost_list) > 1: self.errors.append( '** -AddEdge does not currently work with -multi_cost') else: cstr += '%s%s \\\n' % (istr, '-AddEdge') if len(self.uvars.aea_opts) > 0: cstr += '%s%s \\\n' % (istr, ' '.join(self.uvars.aea_opts)) # does the anatomy have a skull? if self.uvars.anat_has_skull != 'yes': cstr += '%s%s \\\n' % (istr, '-anat_has_skull no') # -epi_strip method if self.uvars.epi_strip_meth != '3dSkullStrip': cstr += '%s%s \\\n' % (istr, '-epi_strip %s' % self.uvars.epi_strip_meth) # want -save_all, -prep_off? # last indent is left by 2 to align () cstr += '%*s)\n\n' % (clen - 2, '') # finally, align the line wrappers cstr = UTIL.add_line_wrappers(cstr) return cmnt + cstr
def script_main(self): """write command with prefix, datasets and extra options """ cmd = SUBJ.comment_section_string('process the data') + '\n' if self.uvars.program == '3dttest++': cmd += self.script_ttest() elif self.uvars.program == '3dMEMA': cmd += self.script_MEMA() else: self.errors.append('** bad program name: %s' % self.uvars.program) return '' return UTIL.add_line_wrappers(cmd)
def make_uber_command(self): """generate a script that would invoke the uber_ttest.py interface with control and user vars set (and so fields filled) Put any key elements in quotes: basis functions gltsym """ if show_func_seq: print('=== xO ===') # first apply subject variables self.update_uvars_from_gui() cmd = 'uber_ttest.py' # apply each uvar with -uvar option prefix = ' \\\n -uvar ' # append before next command for atr in self.uvars.attributes(): if atr == 'name': continue # skip if self.uvars.vals_are_equal(atr, LTT.g_udef_strs): continue # show this one val = self.uvars.val(atr) # special cases first: stim_basis, gltsym #if atr == 'gltsym': # special case # val = ["'%s'" % v for v in val] #elif atr == 'stim_basis': # special case # val = ["'%s'" % v for v in val] # cmd += (prefix + '%s %s' % (atr, ' '.join(val))) # some options might need quotes if self.uvars.has_simple_type(atr): val = UTIL.quotize_list([val], quote_chars='#%<>')[0] cmd += (prefix + '%s %s' % (atr, val)) elif type(val) == list: val = UTIL.quotize_list(val, quote_chars='#%<>') cmd += (prefix + '%s %s' % (atr, ' '.join(val))) else: print('** make_uber_command: bad attr %s' % atr) return UTIL.add_line_wrappers(cmd + '\n')
def make_script(self): """create the review EPI (plugout_drive) script""" c2 = "#!/bin/tcsh\n\n" c2 += "# ------------------------------------------------------\n" \ "# review EPI data via 'afni' and 'plugout_drive'\n\n" \ "# note that when running this script, prompts to change\n" \ "# datasets will appear in the terminal window\n\n" c2 += "# ------------------------------------------------------\n" \ "# set the list of datasets\n" \ "set dsets = ( %s )\n\n" % \ ' '.join([dset.prefix for dset in self.adsets]) c2 += '# ------------------------------------------------------\n' \ '# verify that the input data exists\n' \ 'if ( ! -f $dsets[1]+orig.HEAD ) then\n' \ ' echo "** missing data to review (e.g. $dsets[1])"\n' \ ' exit\n' \ 'endif\n\n' c2 += '# ------------------------------------------------------\n' \ '# start afni is listening mode, and take a brief nap\n\n' \ 'afni -yesplugouts &\n\n' \ 'sleep 5\n\n' cmd = UTIL.add_line_wrappers(c2) c2 = '# ------------------------------------------------------\n' \ '# tell afni to load the first dataset and open windows\n\n' \ 'plugout_drive \\\n' \ ' -com "SWITCH_UNDERLAY %s" \\\n' \ % self.adsets[0].prefix # open windows in the list if self.verb > 1: print '++ opening windows: %s' % ', '.join(self.windows) for ind in range(len(self.windows)): c2 += ' -com "OPEN_WINDOW %simage \\\n' \ ' geom=%dx%d+%d+%d" \\\n' % \ (self.windows[ind], self.im_size[0], self.im_size[1], self.im_xoff+ind*self.im_size[0], self.im_yoff) c2 += ' -com "OPEN_WINDOW sagittalgraph \\\n' \ ' geom=%dx%d+%d+%d" \\\n' % \ (self.gr_size[0], self.gr_size[1], self.gr_xoff, self.gr_yoff) # terminate the initial plugout_drive command c2 += ' -quit\n\n' c2 = UTIL.add_line_wrappers(c2) # do it early, for verb if self.verb > 2: print 'initial drive command:\n%s' % c2 cmd += c2 cmd += 'sleep 2 # give afni time to open the windows\n\n\n' c2 = '# ------------------------------------------------------\n' \ '# process each dataset using video mode\n\n' \ 'foreach dset ( $dsets )\n' \ ' plugout_drive \\\n' \ ' -com "SWITCH_UNDERLAY $dset" \\\n' \ ' -com "OPEN_WINDOW sagittalgraph \\\n' \ ' keypress=a\\\n' \ ' keypress=v"\\\n' \ ' -quit\n\n' \ ' sleep 2 # wait for plugout_drive output\n\n' \ ' echo ""\n' \ ' echo "++ now viewing $dset, hit enter to continue"\n' \ ' set ret = $< # wait for user to hit enter\n' \ 'end\n\n\n' cmd += UTIL.add_line_wrappers(c2) c2 = '# ------------------------------------------------------\n' \ '# stop video mode when the user is done\n\n' \ 'plugout_drive -com "OPEN_WINDOW sagittalgraph keypress=s"' \ ' -quit\n\n\n' \ 'sleep 2 # wait for plugout_drive output\n\n' \ 'echo ""\n' \ 'echo "data review complete"\n\n\n' cmd += UTIL.add_line_wrappers(c2) c2 = '# ----------------------------------------------------------'\ "------\n# auto-generated by gen_epi_review.py, %s\n" % g_version c2 += "#\n# %s %s\n" % (os.path.basename(sys.argv[0]), ' '.join( UTIL.quotize_list(sys.argv[1:], ''))) cmd += UTIL.add_line_wrappers(c2) fp = open(self.script, "w") if not fp: print '** failed to open %s for writing decon script' % self.script return 1 fp.write(cmd) fp.close() try: os.chmod(self.script, 0755) except OSError, e: print e