+ changed parameter handling a bit (input files command line args and not inside...
[qpalma.git] / scripts / qpalma_pipeline.py
index ac7194e..362e5f6 100644 (file)
@@ -20,6 +20,7 @@ import sys
 
 from qpalma.gridtools import ApproximationTask,PreprocessingTask
 from qpalma.gridtools import AlignmentTask,PostprocessingTask
+from qpalma.gridtools import TrainingTask
 
 from qpalma.DatasetUtils import generatePredictionDataset,generateTrainingDataset
 
@@ -27,8 +28,19 @@ from qpalma.SettingsParser import parseSettings
 
 from qpalma.utils import logwrite
 
+Errormsg = """Usage is:  
+                  
+                  python qpalma_pipeline.py train <config filename> <training data filename>
+              or
+                  python qpalma_pipeline.py predict <config filename> <parameter filename> <putative unspliced reads filename> <putative spliced reads filename>
+                  
+           """
 
-Errormsg = """Usage is: python qpalma_pipeline.py predict|train <config filename>"""
+
+def printMessage(mes):
+   print '#'*80
+   print '\t\t\t%s...\n'%mes
+   print '#'*80
 
 
 class System:
@@ -53,7 +65,7 @@ class System:
       logwrite('Parsed settings system set up.',self.settings)
 
 
-   def training(self):
+   def training(self, training_data_fn):
       """
       This function is responsible for the whole training process. It first
       converts the data to the right format needed by QPalma for the training
@@ -61,19 +73,15 @@ class System:
       """
       logwrite('Begin of training.\n',self.settings)
 
-      print '#'*80
-      print '\t\t\tStarting approximation...\n'
-      print '#'*80
+      printMessage('Starting dataset generation')
 
-      # 
-      pre_task = TrainingPreprocessingTask(self.settings)
-      pre_task.createJobs()
-      pre_task.submit() 
-      pre_task.checkIfTaskFinished()
+      self.settings['training_data_fn'] = training_data_fn
 
       # Collect the data and create a pickled training set
       generateTrainingDataset(self.settings)
 
+      printMessage('Starting training')
+
       # Now that we have a dataset we can perform training
       train_task = TrainingTask(self.settings)
       train_task.CreateJobs()
@@ -83,7 +91,7 @@ class System:
       logwrite('End of training.\n',self.settings)
 
 
-   def prediction(self):
+   def prediction(self, param_fn, unspliced_reads_fn, spliced_reads_fn):
       """
       This function encapsulates all steps needed to perform a prediction. Given
       the parameter of the training and paths to a prediction set it will
@@ -92,30 +100,28 @@ class System:
 
       logwrite('Begin of prediction.\n',self.settings)
 
-      print '#'*80
-      print '\t\t\tStarting approximation...\n'
-      print '#'*80
+      printMessage('Starting approximation')
+
+      self.settings['prediction_param_fn'] = param_fn
+      self.settings['unspliced_reads_fn']  = unspliced_reads_fn
+      self.settings['spliced_reads_fn']    = spliced_reads_fn
 
       # Before creating a candidate spliced read dataset we have to first filter
       # the matches from the first seed finding run.
 
-      #approx_task = ApproximationTask(self.settings)
-      #approx_task.CreateJobs()
-      #approx_task.Submit()
-      #approx_task.CheckIfTaskFinished()
+      approx_task = ApproximationTask(self.settings)
+      approx_task.CreateJobs()
+      approx_task.Submit()
+      approx_task.CheckIfTaskFinished()
       
       # After filtering combine the filtered matches from the first run and the
       # found matches from the second run to a full dataset
 
-      print '#'*80
-      print '\t\t\tStarting dataset generation...\n'
-      print '#'*80
+      printMessage('Starting dataset generation')
 
       generatePredictionDataset(self.settings)
 
-      print '#'*80
-      print '\t\t\tStarting alignments...\n'
-      print '#'*80
+      printMessage('Starting alignments')
 
       # Now that we have a dataset we can perform accurate alignments
       align_task = AlignmentTask(self.settings)
@@ -123,9 +129,7 @@ class System:
       align_task.Submit()
       align_task.CheckIfTaskFinished()
 
-      print '#'*80
-      print '\t\t\tPostprocessing...\n'
-      print '#'*80
+      printMessage('Postprocessing')
 
       # The results of the above alignment step can be converted to a data format
       # needed for further postprocessing.
@@ -138,17 +142,32 @@ class System:
    
 
 if __name__ == '__main__':
+   if len(sys.argv) != 4 and len(sys.argv) != 6:
+      print 'Invalid number of arguments!'
+      print len(sys.argv)
+      print Errormsg
+      sys.exit(1)
+
    mode     = sys.argv[1]
-   assert mode in ['predict','train'], Errormsg
+   if not mode in ['predict','train']:
+      print Errormsg
+      sys.exit(1)
+
    filename = sys.argv[2]
-   assert os.path.exists(filename), Errormsg
+   if not os.path.exists(filename):
+      print Errormsg
+      sys.exit(1)
 
    # creating system object
    system_obj = System(filename)
 
    if mode == 'predict':
-      system_obj.prediction()
+      param_fn           = sys.argv[3]
+      unspliced_reads_fn = sys.argv[4]
+      spliced_reads_fn   = sys.argv[5]
+      system_obj.prediction(param_fn,unspliced_reads_fn, spliced_reads_fn)
    elif mode == 'train':
-      system_obj.training()
+      training_data_fn   = sys.argv[3]
+      system_obj.training(training_data_fn)
    else:
       assert False