def setupProgram(): ### Basic Setup of Program ''' Basic setup of Program: - Reads sys.argv and augments if appropriate - Makes Info, Out and Log objects - Returns [info,out,log,cmd_list] ''' ### <0> ### Objects setup try: ## <a> ## Initial Command Setup & Info cmd_list = sys.argv[1:] info = makeInfo() cmd_list = rje.getCmdList( cmd_list, info=info) ### Load defaults from program.ini ## <b> ## Out object out = rje.Out(cmd_list=cmd_list) out.verbose(0, 2, cmd_list, 1) out.printIntro(info) ## <c> ## Additional commands cmd_list = cmdHelp(info, out, cmd_list) ## <d> ## Log log = rje.setLog(info=info, out=out, cmd_list=cmd_list) return [info, out, log, cmd_list] except SystemExit: sys.exit() except: print "Problem during initial setup." raise
def cmdHelp( info=None, out=None, cmd_list=[]): ### Prints *.__doc__ and asks for more sys.argv commands '''Prints *.__doc__ and asks for more sys.argv commands.''' try: if info == None: info = makeInfo() if out == None: out = rje.Out() help = cmd_list.count('help') + cmd_list.count( '-help') + cmd_list.count('-h') if help > 0: print "\n\nHelp for " + info.program + " V:" + info.version + ": " + time.asctime( time.localtime(info.start_time)) + "\n" out.verbose(-1, -1, text=__doc__) sys.exit() elif out.stat['Interactive'] > 1: # Ask for more commands cmd_list += rje.inputCmds(out, cmd_list) return cmd_list except SystemExit: sys.exit() except KeyboardInterrupt: sys.exit() except: print 'Major Problem with cmdHelp()'
def cmdHelp( info=None, out=None, cmd_list=[]): ### Prints *.__doc__ and asks for more sys.argv commands '''Prints *.__doc__ and asks for more sys.argv commands.''' try: ### ~ [1] ~ Setup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### if not info: info = makeInfo() if not out: out = rje.Out() ### ~ [2] ~ Look for help commands and print options if found ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### help = cmd_list.count('help') + cmd_list.count( '-help') + cmd_list.count('-h') if help > 0: print '\n\nHelp for %s %s: %s\n' % ( info.program, info.version, time.asctime(time.localtime(info.start_time))) out.verbose(-1, 4, text=__doc__) if rje.yesNo('Show general commandline options?'): out.verbose(-1, 4, text=rje.__doc__) if rje.yesNo('Quit?'): sys.exit() # Option to quit after help cmd_list += rje.inputCmds( out, cmd_list) # Add extra commands interactively. elif out.stat['Interactive'] > 1: cmd_list += rje.inputCmds(out, cmd_list) # Ask for more commands ### ~ [3] ~ Return commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### return cmd_list except SystemExit: sys.exit() except KeyboardInterrupt: sys.exit() except: print 'Major Problem with cmdHelp()'
def cmdHelp( info=None, out=None, cmd_list=[]): ### Prints *.__doc__ and asks for more sys.argv commands '''Prints *.__doc__ and asks for more sys.argv commands.''' try: if info == None: info = makeInfo() if out == None: out = rje.Out() help = cmd_list.count('help') + cmd_list.count( '-help') + cmd_list.count('-h') if help > 0: print('\n\nHelp for %s %s: %s\n' % (info.program, info.version, time.asctime(time.localtime(info.start_time)))) out.verbose(-1, 4, text=__doc__) if rje.yesNo('Show general commandline options?'): out.verbose(-1, 4, text=rje.__doc__) if rje.yesNo('Quit?'): sys.exit() cmd_list += rje.inputCmds(out, cmd_list) elif out.stat['Interactive'] > 1: # Ask for more commands cmd_list += rje.inputCmds(out, cmd_list) return cmd_list except SystemExit: sys.exit() except KeyboardInterrupt: sys.exit() except: print('Major Problem with cmdHelp()')
def setupProgram(): ### Basic Setup of Program ''' Basic setup of Program: - Reads sys.argv and augments if appropriate - Makes Info, Out and Log objects - Returns [info,out,log,cmd_list] ''' try: ### Initial Command Setup & Info ### info = makeInfo() cmd_list = rje.getCmdList( sys.argv[1:], info=info) ### Load defaults from program.ini ### Out object ### out = rje.Out(cmd_list=cmd_list) out.verbose(2, 2, cmd_list, 1) out.printIntro(info) ### Additional commands ### cmd_list = cmdHelp(info, out, cmd_list) ### Log ### log = rje.setLog(info=info, out=out, cmd_list=cmd_list) return [info, out, log, cmd_list] except SystemExit: sys.exit() except KeyboardInterrupt: sys.exit() except: print 'Problem during initial setup.' raise
def setupProgram(): ### Basic Setup of Program when called from commandline. ''' Basic Setup of Program when called from commandline: - Reads sys.argv and augments if appropriate - Makes Info, Out and Log objects - Returns [info,out,log,cmd_list] ''' try: ### ~ [1] ~ Initial Command Setup & Info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### info = makeInfo() # Sets up Info object with program details cmd_list = rje.getCmdList( sys.argv[1:], info=info) # Reads arguments and load defaults from program.ini out = rje.Out(cmd_list=cmd_list ) # Sets up Out object for controlling output to screen out.verbose(2, 2, cmd_list, 1) # Prints full commandlist if verbosity >= 2 out.printIntro( info) # Prints intro text using details from Info object cmd_list = cmdHelp( info, out, cmd_list) # Shows commands (help) and/or adds commands from user log = rje.setLog( info, out, cmd_list) # Sets up Log object for controlling log file output return (info, out, log, cmd_list) # Returns objects for use in program except SystemExit: sys.exit() except KeyboardInterrupt: sys.exit() except: print 'Problem during initial setup.' raise
def cmdHelp( info=None, out=None, cmd_list=[]): ### Prints *.__doc__ and asks for more sys.argv commands '''Prints *.__doc__ and asks for more sys.argv commands.''' try: if info == None: info = makeInfo() if out == None: out = rje.Out([]) help = cmd_list.count('help') + cmd_list.count( '-help') + cmd_list.count('-h') if help > 0: print "\n\nHelp for " + info.program + " V:" + info.version + ": " + time.asctime( time.localtime(info.start_time)) + "\n" out.verbose(out.verbosity, out.interactive, __doc__, 1) out.verbose(out.verbosity, out.interactive, rje.__doc__, 1) # ! # Add additional user modules and objects here! cmd_list += rje.inputCmds(out, cmd_list) elif out.interactive > 0: # Ask for more commands cmd_list += rje.inputCmds(out, cmd_list) return cmd_list except KeyboardInterrupt: raise except: print 'Major Problem with cmdHelp()'
def cmdHelp( info=None, out=None, cmd_list=[]): ### Prints *.__doc__ and asks for more sys.argv commands '''Prints *.__doc__ and asks for more sys.argv commands.''' try: if not info: info = makeInfo() if len(sys.argv) == 2 and sys.argv[1] in [ 'version', '-version', '--version' ]: rje.printf(info.version) sys.exit(0) if len(sys.argv) == 2 and sys.argv[1] in [ 'details', '-details', '--details' ]: rje.printf('{0} v{1}'.format(info.program, info.version)) sys.exit(0) if not out: out = rje.Out() help = cmd_list.count('help') + cmd_list.count( '-help') + cmd_list.count('-h') if help > 0: rje.printf('\n\nHelp for {0} {1}: {2}\n'.format( info.program, info.version, time.asctime(time.localtime(info.start_time)))) out.verbose(-1, 4, text=__doc__) if rje.yesNo('Show general commandline options?'): out.verbose(-1, 4, text=rje.__doc__) if rje.yesNo('Quit?'): sys.exit() cmd_list += rje.inputCmds(out, cmd_list) elif out.stat['Interactive'] > 1: cmd_list += rje.inputCmds(out, cmd_list) # Ask for more commands return cmd_list except SystemExit: sys.exit() except KeyboardInterrupt: sys.exit() except: rje.printf('Major Problem with cmdHelp()')
def multiHAQ(self, secondrun=False): ### Executes main HAQESAC runs '''Executes main HAQESAC runs.''' try: ### ~ [0] Setup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### finalrun = secondrun == self.opt[ 'MultiHAQ'] # Whether this is the manual HAQESAC phase qryacc = self.obj['SeqList'].accList( ) # Full list of Query accession numbers processed = [] # List of processed sequence accession numbers ### ~ [1] Peform HAQESAC runs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### for seq in self.seqs(): ## ~ [1a] Check AutoSkip ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## acc = seq.info['AccNum'] if finalrun and acc in processed and ( self.opt['AutoSkip'] or (self.i() >= 0 and rje.yesNo( '%s already covered by previous HAQESAC. Skip?' % seq.shortName()))): self.printLog( '#SKIP', '%s already covered by previous HAQESAC: Skipped' % seq.shortName()) continue ## ~ [1b] Check Whether to run (re-runs and low sequence number) ~~~~~~~~~~~~~~~~~~ ## logfile = rje.makePath('%s%s.log' % (self.info['HaqDir'], acc), wholepath=True) infile = rje.makePath('%s%s.fas' % (self.info['HaqDir'], acc), wholepath=True) pkfile = rje.makePath('%s%s.pickle' % (self.info['HaqDir'], acc), wholepath=True) pkzfile = rje.makePath('%s%s.pickle.gz' % (self.info['HaqDir'], acc), wholepath=True) if not os.path.exists(infile): self.printLog( '#SKIP', '%s input file %s not found: Skipped' % (seq.shortName(), infile)) continue if not finalrun and not self.opt['Force'] and rje.isYounger( pkzfile, infile) == pkzfile: self.printLog('#SKIP', '%s run detected: Skipped' % seq.shortName()) continue if not finalrun and not self.opt['Force'] and rje.isYounger( pkfile, infile) == pkfile: self.printLog('#SKIP', '%s run detected: Skipped' % seq.shortName()) continue inseqx = rje_seq.SeqCount(self, infile) if inseqx < 2: self.printLog( '#SKIP', 'Only one sequence found in %s: Skipped' % (infile)) continue ## ~ [1c] Pause if running in Chaser Mode and no Pickle ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## pickled = os.path.exists(pkfile) or os.path.exists( '%s.gz' % pkfile) tm = 0 while secondrun and self.opt['Chaser'] and not pickled: self.progLog( '#WAIT', 'No %s pickle. Sleeping for %d min.' % (acc, tm)) time.sleep(60 * tm) tm += 1 pickled = os.path.exists(pkfile) or os.path.exists( '%s.gz' % pkfile) if not pickled: try: rje.choice( 'Press <ENTER> to try again, or <CTRL+C> to Quit' ) except: self.printLog('#PICKLE', 'No %s pickle.' % (acc, tm)) self.printLog('\r#MULTI', 'Exiting multiHAQ "Chaser" run.') return ## ~ [1d] Run HAQESAC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## runhaqesac = True pngfile = rje.makePath('%s%s.png' % (self.info['HaqDir'], acc), wholepath=True) if not self.force() and rje.exists(pngfile): self.printLog( '#SKIP', 'Found evidence of completed run: %s (force=F). Skipping.' % pngfile) runhaqesac = False ancfile = rje.makePath('%s%s.anc.fas' % (self.info['HaqDir'], acc), wholepath=True) if not self.force() and rje.exists(ancfile): self.printLog( '#SKIP', 'Found evidence of completed run: %s (force=F). Skipping.' % ancfile) runhaqesac = False #if not finalrun or self.opt['Force'] or rje.isYounger(logfile,nsfile) != logfile: if runhaqesac: haqcmd = [ 'ini=haqesac.ini', 'seqin=%s.fas' % acc, 'query=%s' % acc, 'basefile=%s' % acc, 'newlog=F' ] self.printLog( '#HAQ', 'Running HAQESAC for %s - will have own log etc.' % seq.shortName(), log=False) os.chdir(self.info['HaqDir']) info = haqesac.makeInfo() haqcmd = rje.getCmdList(haqcmd, info=info) out = rje.Out( cmd_list=haqcmd ) # Sets up Out object for controlling output to screen out.printIntro( info ) # Prints intro text using details from Info object haqlog = rje.setLog( info, out, haqcmd ) # Sets up Log object for controlling log file output try: haqesac.HAQESAC(log=haqlog, cmd_list=haqcmd).run(setobjects=True) except: os.chdir(self.info['RunPath']) if self.i() >= 0 and rje.yesNo( 'Problem with %s HAQESAC run. Abort?' % seq.shortName()): raise KeyboardInterrupt os.chdir(self.info['RunPath']) if finalrun: self.printLog( '#HAQ', 'HAQESAC final round run for %s' % seq.shortName()) else: self.printLog( '#HAQ', 'HAQESAC first round run for %s' % seq.shortName()) ## ~ [1e] Update ScreenQry ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## if not self.opt['ScreenQry'] or not finalrun: continue qacclist = [] for qacc in rje_seq.SeqList( self.log, ['seqin=%s' % infile, 'autoload=T', 'autofilter=F' ]).accList(): if qacc in qryacc and qacc != acc: qacclist.append(qacc) if qacc in qryacc and qacc not in processed: processed.append(qacc) self.printLog( '#QRY', '%d other queries found in %s: [%s]' % (len(qacclist), infile, string.join(qacclist, '; '))) self.printLog( '#QRY', '%d of %d queries processed' % (len(processed), self.seqNum())) ### ~ [2] MultiHAQ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### if not finalrun: self.printLog('#MULTI', 'Executing second round of multiHAQ') self.multiHAQ(True) except: self.errorLog('Major problem with MultiHAQ.multiHAQ', quitchoice=True)
def setup(self): ### Main class setup method. '''Main class setup method.''' try: ### ~ [1] ~ Setup Program ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### self.obj['Prog'] = None prog = self.getStrLC('Name') if prog in mod: i = self.obj['ProgInfo'] = mod[prog].makeInfo() self.printLog( '#PROG', '%s V%s: %s' % (i.program, i.version, i.description)) progcmd = rje.getCmdList( [], info=i) + self.cmd_list + ['newlog=F'] out = rje.Out(cmd_list=progcmd) out.printIntro(i) if self.getBool('Help'): progcmd = mod[prog].cmdHelp(i, out, ['help'] + progcmd) purgelist = seqsuite.purgelist self.printLog('#CMD', 'Full %s CmdList: %s' % (i.program, rje.argString( rje.tidyArgs(progcmd, nopath=self.getStrLC('Rest') and not self.dev(), purgelist=purgelist))), screen=False) #self.debug(prog) ## ~ [1a] ~ Make self.obj['Prog'] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## if prog in ['slimcore', 'rje_slimcore']: self.obj['Prog'] = rje_slimcore.SLiMCore(self.log, progcmd) elif prog in ['rlc', 'disorder']: self.obj['Prog'] = rje_slimcore.SLiMCore( self.log, progcmd + ['prog=%s' % prog]) elif prog in ['slimlist', 'rje_slimlist']: self.obj['Prog'] = rje_slimlist.SLiMList(self.log, progcmd) elif prog in ['slimfinder']: self.obj['Prog'] = slimfinder.SLiMFinder(self.log, progcmd) elif prog in ['qslimfinder']: self.obj['Prog'] = qslimfinder.QSLiMFinder( self.log, progcmd) elif prog in ['slimprob']: self.obj['Prog'] = slimprob.SLiMProb(self.log, progcmd) elif prog in ['slimmaker']: self.obj['Prog'] = slimmaker.SLiMMaker(self.log, progcmd) elif prog in ['slimfarmer', 'farm']: self.obj['Prog'] = slimfarmer.SLiMFarmer(self.log, progcmd) elif prog in ['slimbench']: self.obj['Prog'] = slimbench.SLiMBench(self.log, progcmd) elif prog in ['comparimotif']: self.obj['Prog'] = comparimotif.CompariMotif( self.log, progcmd) elif prog in ['peptcluster']: self.obj['Prog'] = peptcluster.PeptCluster( self.log, progcmd) elif prog in ['peptalign']: self.obj['Prog'] = peptcluster.PeptCluster( self.log, ['peptalign=T'] + progcmd) self.obj['Prog'].dict['Output']['help'] = mod[prog].__doc__ elif prog in seqsuite.mod: seqsuiteobj = seqsuite.SeqSuite(self.log, self.cmd_list) self.obj['Prog'] = seqsuiteobj.setup() self.obj['ProgInfo'] = seqsuiteobj.obj['ProgInfo'] self.obj['Prog'].dict['Output']['help'] = seqsuite.mod[ prog].__doc__ ### ~ [2] ~ Failure to recognise program ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### if not self.obj['Prog']: self.printLog( '#ERR', 'Program "%s" not recognised.' % self.getStr('Name')) if self.i() < 0: return False #!# Try SeqSuite? #!# if rje.yesNo('Show SLiMSuite help with program options?'): extracmd = cmdHelp(cmd_list=['help'])[1:] if extracmd: self.cmd_list += extracmd self._cmdList() if prog != self.getStrLC('Name'): return self.setup() self.setStr({ 'Name': rje.choice('Give program name (Blank or CTRL+C to quit)') }) if self.getStrLC('Name'): return self.setup() else: return False return self.obj['Prog'] # Setup successful except KeyboardInterrupt: return False except SystemExit: raise except: self.errorLog('Problem during %s setup.' % self.prog()) return False # Setup failed
def setup(self): ### Main class setup method. '''Main class setup method.''' try: ### ~ [1] ~ Setup Program ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### self.obj['Prog'] = None prog = self.getStrLC('Name') if prog in mod: i = self.obj['ProgInfo'] = mod[prog].makeInfo() self.printLog( '#PROG', '%s V%s: %s' % (i.program, i.version, i.description)) progcmd = rje.getCmdList( [], info=i) + self.cmd_list + ['newlog=F'] out = rje.Out(cmd_list=progcmd) out.printIntro(i) #self.debug(prog); self.debug(progcmd) if self.getBool('Help'): progcmd = mod[prog].cmdHelp(i, out, ['help'] + progcmd) self.printLog('#CMD', 'Full %s CmdList: %s' % (i.program, rje.argString( rje.tidyArgs(progcmd, nopath=self.getStrLC('Rest') and not self.dev(), purgelist=purgelist))), screen=False) #self.debug(prog); self.debug(progcmd) ## ~ [1a] ~ Make self.obj['Prog'] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## if prog in ['seqlist', 'rje_seqlist']: self.obj['Prog'] = rje_seqlist.SeqList(self.log, progcmd) elif prog in ['uniprot', 'rje_uniprot']: self.obj['Prog'] = rje_uniprot.UniProt(self.log, progcmd) elif prog in ['taxonomy', 'rje_taxonomy']: self.obj['Prog'] = rje_taxonomy.Taxonomy(self.log, progcmd) elif prog in ['tree', 'rje_tree']: self.obj['Prog'] = rje_tree.Tree(self.log, progcmd) elif prog in ['xref', 'rje_xref']: self.obj['Prog'] = rje_xref.XRef(self.log, progcmd) elif prog in ['seq', 'rje_seq']: self.obj['Prog'] = rje_seq.SeqList(self.log, progcmd) elif prog in ['mitab', 'rje_mitab']: self.obj['Prog'] = rje_mitab.MITAB(self.log, progcmd) elif prog in ['dbase', 'database']: self.obj['Prog'] = rje_dbase.DatabaseController( self.log, progcmd) elif prog in ['pydocs']: self.obj['Prog'] = rje_pydocs.PyDoc(self.log, progcmd) elif prog in ['ensembl', 'rje_ensembl']: self.obj['Prog'] = rje_ensembl.EnsEMBL(self.log, progcmd) elif prog in ['genbank', 'rje_genbank']: self.obj['Prog'] = rje_genbank.GenBank(self.log, progcmd) elif prog in ['extatic']: self.obj['Prog'] = extatic.ExTATIC(self.log, progcmd) elif prog in ['revert']: self.obj['Prog'] = revert.REVERT(self.log, progcmd) elif prog in ['fiesta']: self.obj['Prog'] = fiesta.FIESTA(self.log, progcmd) elif prog in ['gablam']: self.obj['Prog'] = gablam.GABLAM(self.log, progcmd) elif prog in ['gopher']: self.obj['Prog'] = gopher.Gopher(self.log, progcmd) elif prog in ['haqesac']: self.obj['Prog'] = haqesac.HAQESAC(self.log, progcmd) elif prog in ['multihaq']: self.obj['Prog'] = multihaq.MultiHAQ(self.log, progcmd) elif prog in ['pingu']: self.obj['Prog'] = pingu.PINGU(self.log, progcmd) elif prog in ['pacbio']: self.obj['Prog'] = rje_pacbio.PacBio(self.log, progcmd) elif prog in ['rje_zen', 'zen']: self.obj['Prog'] = rje_zen.Zen(self.log, progcmd) ### ~ [2] ~ Failure to recognise program ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### if not self.obj['Prog']: self.printLog( '#ERR', 'Program "%s" not recognised.' % self.getStr('Name')) if self.i() < 0: return False if rje.yesNo('Show SeqSuite help with program options?'): extracmd = cmdHelp(cmd_list=['help'])[1:] if extracmd: self.cmd_list += extracmd self._cmdList() if prog != self.getStrLC('Name'): return self.setup() self.setStr({ 'Name': rje.choice('Give program name (Blank or CTRL+C to quit)') }) if self.getStrLC('Name'): return self.setup() else: return False return self.obj['Prog'] # Setup successful except KeyboardInterrupt: return False except SystemExit: raise except: self.errorLog('Problem during %s setup.' % self.prog()) return False # Setup failed