def setUp(self): self.input = [] self.input.append("testdata/FoxP2_SL167.fastq") self.analysis = AnalysisFactory.createAnalysisFromModuleName("FastQC") self.analysis.setInputFiles(self.input, ['fastq'])
def testRun(self): self.ana = AnalysisFactory.createAnalysisFromModuleName("FastQC") self.ana.setInputFiles(self.input_files, self.input_types) self.assertTrue(len(self.input_files) == 1) self.assertTrue(len(self.input_types) == 1) cmds = self.ana.getCommands() print cmds self.assertTrue(len(cmds) == 1) runner = AnalysisRunner(self.ana) res = runner.run() self.assertTrue(res) self.ana.postProcessOutput() output_str = self.ana.output_str self.assertTrue(len(output_str) == 4)
def testRun(self): self.ana = AnalysisFactory.createAnalysisFromModuleName( "ParallelMpileup") self.ana.setInputFiles(self.input_files, self.input_types) self.ana.refgenome = self.refgenome self.assertTrue(len(self.input_files) == 1) self.assertTrue(len(self.input_types) == 1) self.ana.init() cmds = self.ana.getCommands() print cmds self.assertTrue(len(cmds) == 2) runner = AnalysisRunner(self.ana) res = runner.run() self.assertTrue(res) self.ana.postProcessOutput() output_strings = self.ana.output_strings print output_strings for strobj in output_strings: print strobj.output_string self.assertTrue(len(output_strings) == 2)
def setUp(self): self.ana = AnalysisFactory.createAnalysisFromModuleName("FastQC") self.ana.setInputFiles(["../testdata/FoxP2_SL167.fastq"], ['fastq']) print "Input %s" % self.ana.input_files self.db = AnalysisDBFactory(settings.TESTDBNAME)
def createAnalysisRunnerClass(self): print self.args self.dbfactory = AnalysisDBFactory(settings.DBNAME) self.ana = AnalysisFactory.createAnalysisFromModuleName(self.args.analysis) self.ana.setInputFiles (self.args.input,self.args.input_type) self.ana.init() self.ana.setParameters (self.args.param) self.dbfactory.saveAnalysis(self.ana)
def getCommands(self): self.commands = [] self.output_files = [] self.checkDiskSpace() print "Reading genome file" seqs = FastaFile.getSequenceDict(self.refgenome,False) if self.checkInputFiles() == False: raise Exception("Input files [%s] don't exist = can't continue"%(self.input_files)) fileparts = FileUtils.getFileParts(self.input_files[0]) self.basename = fileparts['basename'] for seq in seqs: len = seqs[seq]['len'] i = 1 while i < len: end = i + self.chunk -1 if end > len: end = len regionstr = "%s:%d-%d"%(seq,i,end) tmpana = AnalysisFactory.createAnalysisFromModuleName("SamtoolsMpileup") tmpana.setInputFiles(self.input_files,self.input_types) tmpana.refgenome = self.refgenome tmpana.regionstr = regionstr tmpana.init() tmpcmds = tmpana.getCommands() for cmd in tmpcmds: self.commands.append(cmd) i = i + self.chunk return self.commands
class ObjectCreateCheck(unittest.TestCase ): # Class with unitttest.TestCase as arg - def setUp(self): self.factory = AnalysisFactory() self.ana = self.factory.createAnalysisFromModuleName("Bowtie2") self.ana.param = " -x ../testdata/databases/Arabidopsis_TAIR.9.171 " AnalysisUtils.setInputFiles(self.ana, ["../testdata/FoxP2_SL167.fastq"], ['fastq']) self.ana.init() def testCreateNewAnalysisRunner( self): # Function gets called automatically """New instance should create successfully""" anarun = AnalysisRunner(self.ana) tmpinputs = AnalysisUtils.getInputFiles(anarun.analysis) self.assertTrue(anarun) def testRun(self): anarun = AnalysisRunner(self.ana) res = anarun.run() self.assertTrue(res) def testGetOutput(self): anarun = AnalysisRunner(self.ana) res = anarun.run() anarun.analysis.postProcessOutput() out = anarun.analysis.output_files print out print anarun.analysis.summary_data self.assertTrue(len(out) == 2)
def fetchAnalysisByID(self, id): logging.info(" ========> AnalysisDB Fetching analysis by id : %s" % id) try: sql = "select * from Analysis where ID = %s" % id cur = self.executeQuery(sql) rows = cur.fetchall() if (len(rows) == 1): row = rows[0] name = row[1] ana = AnalysisFactory.createAnalysisFromModuleName(name) ana.id = id ana.owner = row[2] ana.owner_email = row[3] ana.current_status = row[4] ana.output_status = row[5] ana.input_dir = row[6] ana.working_dir = row[7] ana.output_dir = row[8] ana.runtype = row[9] ana.param = row[10] ana.queue = row[11] ana.slurmid = row[12] ana.cores = row[13] ana.mempercore = row[14] ana.last_updated = row[15] ana.date_created = row[16] # Get the data from the linked tables tables = [ 'InputFile', 'ExpectedOutputFile', 'OutputFile', 'Command', 'SlurmValue', 'SummaryValue', 'Status' ] for t in tables: tmpstr = "Analysis" + t query = "select * from %s where AnalysisID=%d" % (tmpstr, id) cur = self.executeQuery(query) rows = cur.fetchall() for r in rows: if t == "Command": ana.commands.append(r[2]) if t == "InputFile": ana.input_files.append(r[2]) ana.input_types.append(r[3]) if t == "ExpectedOutputFile": ana.expected_output_files.append(r[2]) if t == "OutputFile": ana.output_files.append(r[2]) ana.output_types.append(r[3]) if t == "SlurmValue": ana.slurmparams[r[2]] = r[3] if t == "SummaryValue": ana.summary_data[r[2]] = r[3] elif (len(rows) == 0): return None elif len(rows) > 1: logging.error( " ========> AnalysisDB Error fetching analysis. Non unique id %d : %s" % (id, e.args[0])) raise Exception( "ERROR: analysis id should be unique - multiple rows returned. id is [%d]" % id) ana.init() print ana.toString() return ana except sqlite3.Error, e: if self.con: self.con.rollback() logging.error( " ========> AnalysisDB Error fetching analysis id %d : %s" % (id, e.args[0])) raise
class ObjectCreateCheck(unittest.TestCase ): # Class with unitttest.TestCase as arg - def setUp(self): self.dbobj = AnalysisDBFactory(settings.TESTDBNAME) self.ana_fact = AnalysisFactory() self.anaobj = self.ana_fact.createAnalysisFromModuleName("FastQC") self.anaobj.setInputFiles(["../testdata/FoxP2_SL167.fastq"], ['fastq']) def testCreateObject(self): """ Test we can create a new AnalysisDBFactory object """ self.assertTrue(self.dbobj) def testCreateAnalysisTables(self): """ Test we can create the Analysis tables """ self.assertTrue(self.dbobj.createAnalysisTables()) def testGetTables(self): """ Test we can retrive a list of db tables """ self.dbobj.createAnalysisTables() rows = self.dbobj.getTables() self.assertTrue(len(rows) == 9) def testAddAnalysisToDB(self): """ Test we can save an Analysis object to the DB """ #self.dbobj.createAnalysisTables() #self.dbobj.saveAnalysis(self.anaobj) #self.assertTrue(1) def testFetchAnalsyisFromDB(self): """ Test we can fetch an existing analysis object from the DB""" #self.anaobj.id = None #self.dbobj.saveAnalysis(self.anaobj) #ana = self.dbobj.fetchAnalysisByID(self.anaobj.id) #str1 = self.anaobj.toString() #str2 = ana.toString() #self.assertTrue(str1 == str2) def testUpdateAnalysisStatus(self): """ Test updating an analysis objects status""" self.anaobj.id = None self.dbobj.saveAnalysis(self.anaobj) self.dbobj.updateAnalysisStatus(self.anaobj, "RUNNING") ana = self.dbobj.fetchAnalysisByID(self.anaobj.id) str1 = self.anaobj.toString() str2 = ana.toString() print "STR1 %s" % str1 print "STR2 %s" % str2 self.assertTrue(ana.current_status == "RUNNING")