Public Member Functions | Static Public Attributes

MGT::App::App Class Reference

Inheritance diagram for MGT::App::App:
MGT::CrossValidatorApp::CrossValidatorApp MGT::ImmApp::ImmApp MGT::ImmClassifierApp::ImmClassifierApp MGT::ImmScalingApp::ImmScalingApp MGT::ParamScanApp::ParamScanApp MGT::ParamScanTestApp::ParamScanTestApp MGT::PhageHostApp::PhageHostApp MGT::Proj::CrisprApp::CrisprApp MGT::Proj::GbFeatApp::GbFeatApp MGT::Proj::HctApp::HctApp MGT::Proj::PhHostGosApp::PhHostGosApp MGT::Proj::SynecApp::SynecApp MGT::TreeSamplerApp::TreeSamplerApp

List of all members.

Public Member Functions

def __init__
def run
def initWork
def doWork
def runBatch
def parseCmdLine
def makeOptionParserArgs
def parseCmdLinePost
def fillWithDefaultOptions
def instanceOptionsPost
def getAppName
def factory
def getCmd
def getCmdOptFile

Static Public Attributes

tuple batchDepModes = tuple()
 Derived classes should set this to a list of opt.mode values that can result in submision of new batch jobs.

Detailed Description

Interface to application object. 
The application can be started from shell scripts or called in-process from Python code.
In both modes, it provides a method to schedule a batch queue execution, possibly
represented as a DAG of dependent jobs.
If you need to run it as a script from shell, call runAppAsScript from module level,
passing the proper derived class (see code example at the bottom of this source file).
The uniform way of providing scripting interface is to place each App derived class in
its own source file with the same name as the class, and include the mentioned
code snippet at the bottom.

Constructor & Destructor Documentation

def MGT::App::App::__init__ (   self,
  args = [],
  opt = Struct() 
)
Constructor.
@param args optional command line arguments to parse -
if executing as a module, should pass None or sys.argv[1:], else - [], which should result in 
default values generated for all options not defined by opt.
@param opt Struct instance - values defined here will override those parsed from args.
Two basic use patterns: 
if running as a shell script and parsing actual command line arguments:
    app = App(args=None)
    app.run()
if calling from Python code:
    construct opt as a Struct() instance, specify only attributes with non-default values, then
    app = App(opt=opt) #that fills yet unset options with defaults
    app.run() #either runs in the same process, or submits itself or a set of other Apps to batch queue

Reimplemented in MGT::TreeSamplerApp::TreeSamplerApp.


Member Function Documentation

def MGT::App::App::doWork (   self,
  kw 
)
Do the actual work.
Must be redefined in the derived classes.
Should not be called directly by the user except from doWork() in a derived class.
Should work with empty keyword dict, using only self.opt.
If doing batch submision of other App instances, must return a list of sink (final) BatchJob objects.

Reimplemented in MGT::CrossValidatorApp::CrossValidatorApp, MGT::ImmApp::ImmApp, MGT::ImmClassifierApp::ImmClassifierApp, MGT::ImmScalingApp::ImmScalingApp, MGT::ParamScanApp::ParamScanApp, MGT::ParamScanTestApp::ParamScanTestApp, MGT::PhageHostApp::PhageHostApp, MGT::Proj::CrisprApp::CrisprApp, MGT::Proj::GbFeatApp::GbFeatApp, MGT::Proj::HctApp::HctApp, MGT::Proj::PhHostGosApp::PhHostGosApp, MGT::Proj::SynecApp::SynecApp, and MGT::TreeSamplerApp::TreeSamplerApp.

def MGT::App::App::factory (   self,
  kw 
)
A factory function (class constructor by default) that creates a new instance of self.
This is needed when the application needs to batch-submit a new instance of itself.
def MGT::App::App::fillWithDefaultOptions (   klass,
  options 
)
Fill with default values those options that are not already set.
@param options Existing options object - will be modified in place and also returned
@return Modified options parameter
def MGT::App::App::getAppName (   self )
Return mnemonic name for this application to use for example as a prefix of batch script name
def MGT::App::App::getCmd (   self )
Return command line that starts this application from shell, w/o options.
"python -c '...'" form is used if we can get the module name of self,
and "python sys.argv[0]" otherwise.
def MGT::App::App::getCmdOptFile (   self,
  cwd = os.getcwd(),
  kw 
)
Generate unique file name for a new options pickle file and build full command line with it.
@param cwd optional directory for the new file (current dir by default)
@ret Struct(optFile,cmd) where optFile is file name, cmd is command line, 
such as self.getCmd()+' --opt-file '+optFile.
def MGT::App::App::initWork (   self,
  kw 
)
Perform common initialization right before doing the actual work in doWork().
Must be redefined in the derived classes.
Should not be called directly by the user except from initWork() in a derived class.
This one can create large objects because they are not passed through the batch submission,
but immediately used within the same process.

Reimplemented in MGT::ImmApp::ImmApp, MGT::ImmClassifierApp::ImmClassifierApp, MGT::ImmScalingApp::ImmScalingApp, MGT::PhageHostApp::PhageHostApp, MGT::Proj::CrisprApp::CrisprApp, MGT::Proj::GbFeatApp::GbFeatApp, MGT::Proj::PhHostGosApp::PhHostGosApp, and MGT::TreeSamplerApp::TreeSamplerApp.

def MGT::App::App::instanceOptionsPost (   self,
  opt 
)
Set (in place) instance-specific options.
This is called from __init__() and has access to the execution context (such as current dir).
def MGT::App::App::makeOptionParserArgs (   klass )
Return a Struct with optparse.OptionParser constructor arguments specific to the application.
The "option_list" attribute must be obtained with a sequence of calls to optparse.make_option.
Other possible attributes can be e.g. "usage".
This method will be called by parseCmdLine() and the returned "option_list" concatenated with the default
one provided by the parseCmdLine().
Must be redefined in the derived class only if there are any application specific command-line options.

Reimplemented in MGT::ImmClassifierApp::ImmClassifierApp, MGT::ImmScalingApp::ImmScalingApp, and MGT::PhageHostApp::PhageHostApp.

def MGT::App::App::parseCmdLine (   klass,
  args = None,
  _explicitOpt = None 
)
Obtain options from command line arguments.
It is called from constructor or directly by the user.
Derived classes must redefine makeOptionParserArgs() and optionally parseCmdLinePost() 
if they need to parse additional arguments.
The arguments defined here are needed by the App infrastructure: 
--opt-file -> optFile (None); --batch -> batch (False).
When called directly from the user code, the args is typically set to [] in order to obtain
the default values for all options. Thus, it is important the the implementation provides
reasonable defaults in a context independent way (e.g. without including the current directory info).
@param args command line arguments (pass [] to get default values, pass None to use sys.argv[1:])
def MGT::App::App::parseCmdLinePost (   klass,
  options,
  args,
  parser 
)
Optionally modify options and args in-place.
Called at the end of parseCmdLine to allow the derived classes customizing the option processing.
@param options options returned by OptionParser and converted to Struct object
@param args args returned by OptionParser
@param parser OptionParser object used to parse the command line - needed here to call its error() method
if necessary.
options should be modified in place by this method

Reimplemented in MGT::ImmApp::ImmApp, MGT::ImmClassifierApp::ImmClassifierApp, MGT::ImmScalingApp::ImmScalingApp, MGT::ParamScanTestApp::ParamScanTestApp, MGT::PhageHostApp::PhageHostApp, MGT::Proj::CrisprApp::CrisprApp, MGT::Proj::GbFeatApp::GbFeatApp, MGT::Proj::HctApp::HctApp, MGT::Proj::PhHostGosApp::PhHostGosApp, and MGT::Proj::SynecApp::SynecApp.

def MGT::App::App::run (   self,
  kw 
)
Run the application. 
This is the method that is actually called by the user code. 
Dispatches the work execution or batch submission depending on the options.
@return list of sink BatchJob objects (if executed syncroniously, an empty list)
def MGT::App::App::runBatch (   self,
  kw 
)
Submit this application to run in batch mode.
Can be redefined in derived classes.
self.getCmdOptFile() will provide support for constructing the command line for batch script.
BatchRun.runBatch() should be used to submit the batch job.
We provide a generic implementation here that just submits itself with current options.
Derived classes can define more complex schemes, e.g. fan out N parallel jobs plus
one that starts on their completion to collect the results. 
Although batch jobs can re-use runBatch() to submit other jobs, the return value of the top-most
runBatch() will not know about these sub-jobs and therefore could not define dependencies on them.
The requirement to this method is that it must have a quick running top-level mode suitable
to call on the login host.
It can be called from both self.run() when 'batch' option is set, and directly from external code.
@return list of BatchJob objects corresponding to the sinks (final vertices) in the DAG of submitted jobs.
If kw["runMode"] or global options.app.runMode == "inproc" it will call self.run() instead of submitting a batch job.

Member Data Documentation

tuple MGT::App::App::batchDepModes = tuple() [static]

The documentation for this class was generated from the following file: