def setUp(self): if FileUtils.fileExists(settings.TESTDBNAME): os.remove(settings.TESTDBNAME) settings.DBNAME = settings.TESTDBNAME init_database() Session = sessionmaker(bind=settings.ENGINE) self.session = Session()
def __init__(self, deltafile, refseqs, qryseqs): self.deltafile = deltafile self.refseqs = refseqs self.qryseqs = qryseqs if not FileUtils.fileExists(self.deltafile): raise Exception( "Can't parse Mummer delta file. File [%s] doesn't exist" % self.deltafile)
def setUp(self): if FileUtils.fileExists(settings.TESTDBNAME): os.remove(settings.TESTDBNAME) settings.DBNAME = settings.TESTDBNAME init_database() #input_files = ['pog1.fa','pog2.fa','pog3.fa'] #input_types = ['fasta','fasta','fasta'] #self.ana = Analysis("FastQC") self.input_files = ["testdata/FoxP2_SL167.fastq"] self.input_types = ['fastq'] Session = sessionmaker(bind=settings.ENGINE) self.session = Session()
def testRunMummer(self): mummer = Mummer() self.assertTrue(mummer) self.assertTrue(AnalysisUtils.setInputFiles(mummer,self.input_files,['fasta','fasta'])) runner = AnalysisRunner(mummer) self.assertTrue(runner.run()) self.assertTrue(len(mummer.output_strings) == 1) self.assertTrue(mummer.output_strings[0].output_string.index('4: FINISHING DATA') > 0) self.assertTrue(FileUtils.fileExists('../testout/mummer.delta'))
def checkBinary(self,binfile): return FileUtils.fileExists(binfile)
def tearDown(self): deltafile = '../testout/mummer.delta' if FileUtils.fileExists(deltafile): os.remove(deltafile)
"""Unit test for Analysis.py""" import os import sys import unittest import logging sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../") from config import settings from datamodel.FileUtils import FileUtils from datamodel.database.DB import Analysis, init_database from datamodel.database.AnalysisUtils import AnalysisUtils from sqlalchemy.orm import sessionmaker if FileUtils.fileExists(settings.TESTLOGFILE): os.remove(settings.TESTLOGFILE) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') fh = logging.FileHandler(settings.TESTLOGFILE, 'a') fh.setFormatter(formatter) log = logging.getLogger() # root logger for hdlr in log.handlers: # remove all old handlers log.removeHandler(hdlr) log.addHandler(fh) # set the new handler class DBAnalysisTest(unittest.TestCase
def getCommands(self): if self.commands and len(self.commands) > 0: return self.commands logging.info(" ========> Analysis %20s Getting commands" % (self.name)) self.commands = [] self.expected_output_files = [] self.temp_output_files = [] outdir = self.output_dir tmpdir = self.working_dir btbin = self.bowtiebindir + self.bowtiebinname stbin = self.samtoolsbindir + self.samtoolsbinname self.calculateSpaceNeeded() if FileUtils.fileExists(btbin) == False: raise Exception("Binary file [%s] doesn't exist = can't continue" % btbin) if FileUtils.fileExists(stbin) == False: raise Exception("Binary file [%s] doesn't exist = can't continue" % stbin) if AnalysisUtils.checkInputFiles(self) == False: raise Exception("Input files [%s] don't exist = can't continue" % (self.input_files)) AnalysisUtils.checkDiskSpace(self) for fobj in self.input_files: f = fobj.input_file try: if f.endswith(".gz"): # f = "<( zcat -c " + f + " )" tmpf = f.replace(".gz", "") fparts = FileUtils.getFileParts(tmpf) command = "gunzip -c " + f + " > " + tmpdir + "/" + fparts[ 'basename'] self.commands.append(command) self.temp_output_files.append(tmpf) f = tmpdir + "/" + fparts['basename'] fparts = FileUtils.getFileParts(f) fstub = fparts['filestub'] bowtieoutfile = tmpdir + "/" + fstub + ".sam" samtoolsoutfile = tmpdir + "/" + fstub + ".bam" if self.param == None: raise Exception( "No parameters entered for bowtie = needs -x <genomeindex>" ) command1 = btbin + " " + self.param + " " + f + " | " + stbin + " view -bS - | " + stbin + " sort - " + tmpdir + "/" + fstub logging.info(" ========> Analysis %20s command 1 : %s" % (self.name, command1)) #command2 = stbin + " view -bS " + bowtieoutfile + "| " + stbin + " sort - " + tmpdir + "/" + fstub # logging.info(" ========> Analysis %20s command 2 : %s" % (self.name,command2)) command2 = stbin + " index " + samtoolsoutfile logging.info(" ========> Analysis %20s command 3 : %s" % (self.name, command2)) # self.expected_output_files.append(fstub + ".sam") self.expected_output_files.append( AnalysisExpectedOutputFile(expected_output_file=fstub + ".bam")) self.expected_output_files.append( AnalysisExpectedOutputFile(expected_output_file=fstub + ".bam.bai")) self.commands.append(AnalysisCommand(command=command1)) self.commands.append(AnalysisCommand(command=command2)) #self.commands.append(command3) except Exception as e: logging.info( " ========> Analysis %20s Failed building command list [%s]" % (self.name, e)) raise return self.commands