def test_numberOfPairs(self): """ --numberOfPairs options should produce expected and known output for given inputs """ mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('numberOfPairs')) i = -1 for maf1, maf2, totalTrue, totalFalse in knownValues: i += 1 testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [] cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')), '--samples=1000', '--logLevel=critical', '--numberOfPairs=%s' % knownValuesNumberOfPairs[i], ] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) passedTT = totalTrue == getAggregateResult(os.path.abspath(os.path.join(tmpDir, 'output.xml')), 'totalTrue') passedTF = totalFalse == getAggregateResult(os.path.abspath(os.path.join(tmpDir, 'output.xml')), 'totalFalse') if not (passedTT and passedTF): print 'knownValues Test failed on test %d' % i self.assertTrue(passedTT and passedTF) mtt.removeDir(tmpDir)
def test_memory_3(self): """ mafComparator should be memory clean for known values using --near option """ valgrind = mtt.which('valgrind') if valgrind is None: return mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('memory_3')) for maf1, maf2, near, totalTrue, totalFalse in knownValuesNear: testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')), '--near=%d' % near, '--samples=1000', '--logLevel=critical', ] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')) self.assertTrue(passed) mtt.removeDir(tmpDir)
def test_memoryTest_4(self): """ --wigglePairs options should be memory clean """ valgrind = mtt.which('valgrind') if valgrind is None: return mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('memory_4')) for maf1, maf2, ref, partner, binlen, valuesDictList in knownValuesWiggles: testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')), '--samples=1000', '--logLevel=critical', '--wigglePairs=%s:%s' % (ref, partner), '--wiggleBinLength=%d' % binlen, ] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')) self.assertTrue(passed) mtt.removeDir(tmpDir)
def testMemory1(self): """ If valgrind is installed on the system, check for memory related errors (1). """ valgrind = mtt.which('valgrind') if valgrind is None: return for i in xrange(0, 10): shuffledBlocks = [] expectedOutput = [] tmpDir = os.path.abspath(mtt.makeTempDir()) order = [1] * len(g_duplicateBlocks) + [0] * len(g_nonDuplicateBlocks) random.shuffle(order) random.shuffle(g_duplicateBlocks) random.shuffle(g_nonDuplicateBlocks) j, k = 0, 0 for dupBlock in order: if dupBlock: shuffledBlocks.append(g_duplicateBlocks[j][0]) expectedOutput.append(g_duplicateBlocks[j][1]) j += 1 else: shuffledBlocks.append(g_nonDuplicateBlocks[k]) expectedOutput.append(g_nonDuplicateBlocks[k]) k += 1 testMaf = mtt.testFile(os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')), ''.join(shuffledBlocks), g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [valgrind, '--leak-check=full', '--show-reachable=yes', '--track-origins=yes', '--xml=yes', '--xml-file=' + os.path.join(tmpDir, 'valgrind.xml')] cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafBlockDuplicateFilter')), '--maf', os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf'))] outpipes = [os.path.abspath(os.path.join(tmpDir, 'filtered.maf'))] mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))) mtt.removeTempDir()
def test_memory_0(self): """ mafComparator should be memory clean for bed parsing examples """ valgrind = mtt.which('valgrind') if valgrind is None: return mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('memory_0')) for maf1, maf2, bed, totalTrue, totalTrueInInterval in knownValuesBed: testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) testBed = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'bed.bed')), bed, ['']) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')), '--samples=1000', '--logLevel=critical', ] if bed != '': cmd += ['--bedFiles', os.path.abspath(os.path.join(tmpDir, 'bed.bed'))] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')) self.assertTrue(passed) mtt.removeDir(tmpDir)
def testFastaStitch(self): """ mafToFastaStitcher should produce known output for a given known input """ mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('fasta')) customOpts = mafval.GenericValidationOptions() for reference, inMaf, inFaList, outFa, outMaf in g_knownData: testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test.maf')), ''.join(inMaf), g_headers) testFaNames = testFasta(os.path.abspath(tmpDir), inFaList) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [] cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafToFastaStitcher')), '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--seqs', testFaNames, '--breakpointPenalty', '6', '--interstitialSequence', '20', '--outMfa', os.path.abspath(os.path.join(tmpDir, 'out.fa')), '--outMaf', os.path.abspath(os.path.join(tmpDir, 'out.maf')),] if reference is not None: cmd += ['--reference', reference] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) self.assertTrue(fastaIsCorrect(os.path.abspath(os.path.join(tmpDir, 'out.fa')), outFa)) self.assertTrue(mafIsCorrect(os.path.abspath(os.path.join(tmpDir, 'out.maf')), outMaf)) self.assertTrue(mafval.validateMaf(os.path.join(tmpDir, 'out.maf'), customOpts)) mtt.removeDir(tmpDir)
def testFilter(self): """ mafDuplicateFilter should filter out duplicates in blocks according to sequence similarity to the consensus. """ mtt.makeTempDirParent() for i in xrange(0, 10): shuffledBlocks = [] expectedOutput = [] tmpDir = os.path.abspath(mtt.makeTempDir('filter')) order = [1] * len(g_duplicateBlocks) + [0] * len(g_nonDuplicateBlocks) random.shuffle(order) random.shuffle(g_duplicateBlocks) random.shuffle(g_nonDuplicateBlocks) j, k = 0, 0 for dupBlock in order: if dupBlock: shuffledBlocks.append(g_duplicateBlocks[j][0]) expectedOutput.append(g_duplicateBlocks[j][1]) j += 1 else: shuffledBlocks.append(g_nonDuplicateBlocks[k]) expectedOutput.append(g_nonDuplicateBlocks[k]) k += 1 testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test.maf')), ''.join(shuffledBlocks), g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafDuplicateFilter')), '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf'))] outpipes = [os.path.abspath(os.path.join(tmpDir, 'filtered.maf'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mafIsFiltered(os.path.join(tmpDir, 'filtered.maf'), expectedOutput)) mtt.removeDir(tmpDir)
def testCoverage_0(self): """ mafCoverage should output numbers that accurately reflect the coverage between sequences. """ mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('testCoverage_0')) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) customOpts = mafval.GenericValidationOptions() for target, mafSeq, solutionDict in g_knownGood: testMaf = mtt.testFile( os.path.join(os.path.abspath(tmpDir), 'test.maf'), mafSeq, g_headers) cmd = [ os.path.abspath(os.path.join(parent, 'test', 'mafCoverage')) ] cmd += [ '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--species', target ] outpipes = [os.path.join(tmpDir, 'output.txt')] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue( mafval.validateMaf(os.path.join(tmpDir, 'test.maf'), customOpts)) self.assertTrue( coverageIsCorrect(os.path.join(tmpDir, 'output.txt'), solutionDict)) mtt.removeDir(tmpDir)
def testMemory0(self): """ If valgrind is installed on the system, check for memory related errors (0). """ valgrind = mtt.which('valgrind') if valgrind is None: return mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('memory_0')) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) customOpts = mafval.GenericValidationOptions() for target, mafSeq, solutionDict in g_knownGood: testMaf = mtt.testFile( os.path.join(os.path.abspath(tmpDir), 'test.maf'), mafSeq, g_headers) cmd = mtt.genericValgrind(tmpDir) cmd.append( os.path.abspath(os.path.join(parent, 'test', 'mafCoverage'))) cmd += [ '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--species', target ] outpipes = [os.path.join('/dev', 'null')] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue( mafval.validateMaf(os.path.join(tmpDir, 'test.maf'), customOpts)) self.assertTrue( mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))) mtt.removeDir(tmpDir)
def testExtraction(self): """ mafBlockExtractor should output blocks that meet the criteria for extraction. That is they contain the taget sequence and have at least one base in the target range. """ for i in xrange(0, 10): shuffledBlocks = [] tmpDir = os.path.abspath(mtt.makeTempDir()) order = [1] * len(g_overlappingBlocks) + [0] * len(g_nonOverlappingBlocks) random.shuffle(order) random.shuffle(g_overlappingBlocks) random.shuffle(g_nonOverlappingBlocks) j, k = 0, 0 for isOverlapping in order: if isOverlapping: shuffledBlocks.append(g_overlappingBlocks[j]) j += 1 else: shuffledBlocks.append(g_nonOverlappingBlocks[k]) k += 1 testMaf = mtt.testFile(os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')), ''.join(shuffledBlocks), g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafBlockExtractor'))] cmd += ['--maf', os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')), '--seq', g_targetSeq, '--start', '%d' % g_targetRange[0], '--stop', '%d' % g_targetRange[1]] outpipes = [os.path.abspath(os.path.join(tmpDir, 'extracted.maf'))] mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mafIsExtracted(os.path.join(tmpDir, 'extracted.maf'))) mtt.removeTempDir()
def testMemory1(self): """ If valgrind is installed on the system, check for memory related errors (1). """ valgrind = mtt.which('valgrind') if valgrind is None: return for i in xrange(0, 10): shuffledBlocks = [] tmpDir = os.path.abspath(mtt.makeTempDir()) order = [1] * len(g_overlappingBlocks) + [0] * len(g_nonOverlappingBlocks) random.shuffle(order) random.shuffle(g_overlappingBlocks) random.shuffle(g_nonOverlappingBlocks) j, k = 0, 0 for isOverlapping in order: if isOverlapping: shuffledBlocks.append(g_overlappingBlocks[j]) j += 1 else: shuffledBlocks.append(g_nonOverlappingBlocks[k]) k += 1 testMaf = mtt.testFile(os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')), ''.join(shuffledBlocks), g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [valgrind, '--leak-check=full', '--show-reachable=yes', '--track-origins=yes', '--xml=yes', '--xml-file=' + os.path.join(tmpDir, 'valgrind.xml')] cmd.append(os.path.abspath(os.path.join(parent, 'test', 'mafBlockExtractor'))) cmd += ['--maf', os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')), '--seq', g_targetSeq, '--start', '%d' % g_targetRange[0], '--stop', '%d' % g_targetRange[1]] outpipes = [os.path.abspath(os.path.join(tmpDir, 'extracted.maf'))] mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))) mtt.removeTempDir()
def dtestMemory2(self): """ If valgrind is installed on the system, check for memory related errors (2). """ valgrind = mtt.which("valgrind") if valgrind is None: return global g_header for i in xrange(0, len(g_nonOverlappingBlocks)): tmpDir = os.path.abspath(mtt.makeTempDir()) testMafPath, g_header = mtt.testFile( os.path.abspath(os.path.join(os.curdir, "tempTestDir", "test.maf")), "".join(g_nonOverlappingBlocks[i][0]), g_headers, ) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [ valgrind, "--leak-check=full", "show-reachable=yes", "--track-origins=yes", "--xml=yes", "--xml-file=" + os.path.join(tmpDir, "valgrind.xml"), ] cmd.append(os.path.abspath(os.path.join(parent, "test", "mafBlockFinder"))) cmd += ["--maf", testMafPath, "--seq", g_targetSeq, "--pos", "%d" % g_nonOverlappingBlocks[i][1]] outpipes = [os.path.abspath(os.path.join(tmpDir, "found.txt"))] mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, "valgrind.xml"))) mtt.removeTempDir()
def testMemory2(self): """ If valgrind is installed on the system, check for memory related errors (2). """ valgrind = mtt.which('valgrind') if valgrind is None: return mtt.makeTempDirParent() i = -1 for inblocks, seq, start, stop, outblocks in self.testSet: i += 1 tmpDir = os.path.abspath(mtt.makeTempDir('memory_2')) random.shuffle(g_nonOverlappingBlocks) testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), ''.join(map(str, inblocks)), g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd.append(os.path.abspath(os.path.join(parent, 'test', 'mafExtractor'))) cmd += ['--maf', os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), '--seq', seq, '--start', '%d' % start, '--stop', '%d' % stop, ] outpipes = [os.path.abspath(os.path.join(tmpDir, 'extracted.maf'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))) mtt.removeDir(tmpDir)
def testHardExtraction_0(self): """ mafExtractor should output trimmed blocks by default. """ valgrind = mtt.which('valgrind') if valgrind is None: return mtt.makeTempDirParent() customOpts = mafval.GenericValidationOptions() i = -1 for inblocks, seq, start, stop, outblocks in self.testSet: i += 1 tmpDir = os.path.abspath(mtt.makeTempDir('hardextraction_0')) testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), ''.join(map(str, inblocks)), g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafExtractor'))] cmd += ['--maf', os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), '--seq', seq, '--start', '%d' % start, '--stop', '%d' % stop, ] outpipes = [os.path.abspath(os.path.join(tmpDir, 'extracted.maf'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mafIsHardExtracted('hardextraction_0_%d' % i, outblocks, os.path.join(tmpDir, 'extracted.maf'))) self.assertTrue(mafval.validateMaf(os.path.join(tmpDir, 'extracted.maf'), customOpts)) mtt.removeDir(tmpDir)
def test_memoryTest_6(self): valgrind = mtt.which('valgrind') if valgrind is None: return mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('memory_6')) i = -1 for maf1, maf2, totalTrue, totalFalse in knownValues: i += 1 testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')), '--samples=1000', '--logLevel=critical', '--numberOfPairs=%s' % knownValuesNumberOfPairs[i], ] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')) self.assertTrue(passed) mtt.removeDir(tmpDir)
def testFind(self): """ mafPositionFinder should report information about matching sequences within blocks. """ global g_header mtt.makeTempDirParent() for i in xrange(0, len(g_overlappingBlocks)): tmpDir = os.path.abspath(mtt.makeTempDir('find')) testMafPath, g_header = mtt.testFile( os.path.abspath(os.path.join(tmpDir, 'test.maf')), g_overlappingBlocks[i][0], g_headers) parent = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) cmd = [ os.path.abspath( os.path.join(parent, 'test', 'mafPositionFinder')) ] cmd += [ '--maf', testMafPath, '--seq', g_targetSeq, '--pos', '%d' % g_overlappingBlocks[i][1] ] outpipes = [os.path.abspath(os.path.join(tmpDir, 'found.txt'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue( foundLines(g_overlappingBlocks[i][2], os.path.join(tmpDir, 'found.txt'), g_header)) mtt.removeDir(tmpDir)
def test_bedParsing(self): """ mafComparator should parse a bed file and use the intervals for testing """ mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('bedParsing')) for maf1, maf2, bed, totalTrue, totalTrueInInterval in knownValuesBed: testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) testBed = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'bed.bed')), bed, ['']) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')), '--samples=1000', '--logLevel=critical', ] if bed != '': cmd += ['--bedFiles', os.path.abspath(os.path.join(tmpDir, 'bed.bed'))] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) passed = xmlBedRegionPassed(os.path.abspath(os.path.join(tmpDir, 'output.xml')), totalTrue, totalTrueInInterval) self.assertTrue(passed) mtt.removeDir(tmpDir)
def testNonFind(self): """ mafPositionFinder should not report any lines when blocks do not match. """ global g_header mtt.makeTempDirParent() for i in xrange(0, len(g_nonOverlappingBlocks)): tmpDir = os.path.abspath(mtt.makeTempDir('nonFind')) testMafPath, g_header = mtt.testFile( os.path.abspath(os.path.join(tmpDir, 'test.maf')), ''.join(g_nonOverlappingBlocks[i][0]), g_headers) parent = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) cmd = [ os.path.abspath( os.path.join(parent, 'test', 'mafPositionFinder')) ] cmd += [ '--maf', testMafPath, '--seq', g_targetSeq, '--pos', '%d' % g_nonOverlappingBlocks[i][1] ] outpipes = [os.path.abspath(os.path.join(tmpDir, 'found.txt'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mtt.fileIsEmpty(os.path.join(tmpDir, 'found.txt'))) mtt.removeDir(tmpDir)
def testorder(self): """ mafRowOrderer should order blocks according to user input """ global g_header mtt.makeTempDirParent() customOpts = mafval.GenericValidationOptions() for i in xrange(0, len(g_blocks)): tmpDir = os.path.abspath(mtt.makeTempDir('order')) testMafPath, g_header = mtt.testFile( os.path.abspath(os.path.join(tmpDir, 'test.maf')), g_blocks[i][0], g_headers) parent = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) cmd = [] cmd.append( os.path.abspath(os.path.join(parent, 'test', 'mafRowOrderer'))) cmd += ['--maf', testMafPath, '--order', '%s' % g_order] outpipes = [os.path.abspath(os.path.join(tmpDir, 'ordered.maf'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) ordered = mafIsOrdered(os.path.join(tmpDir, 'ordered.maf'), g_blocks[i][1], g_header) self.assertTrue( mafval.validateMaf(os.path.join(tmpDir, 'ordered.maf'), customOpts)) self.assertTrue(ordered) if ordered: mtt.removeDir(tmpDir)
def testMemory2(self): """ If valgrind is installed on the system, check for memory related errors (2). """ mtt.makeTempDirParent() valgrind = mtt.which('valgrind') if valgrind is None: return global g_header for i in xrange(0, len(g_nonOverlappingBlocks)): tmpDir = os.path.abspath(mtt.makeTempDir('memory2')) testMafPath, g_header = mtt.testFile( os.path.abspath(os.path.join(tmpDir, 'test.maf')), ''.join(g_nonOverlappingBlocks[i][0]), g_headers) parent = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd.append( os.path.abspath( os.path.join(parent, 'test', 'mafPositionFinder'))) cmd += [ '--maf', testMafPath, '--seq', g_targetSeq, '--pos', '%d' % g_nonOverlappingBlocks[i][1] ] outpipes = [os.path.abspath(os.path.join(tmpDir, 'found.txt'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue( mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))) mtt.removeDir(tmpDir)
def testMemory1(self): """ If valgrind is installed on the system, check for memory related errors (1). """ mtt.makeTempDirParent() valgrind = mtt.which("valgrind") if valgrind is None: return shuffledTargets = list(g_targetBlocks) for i in xrange(0, 20): tmpDir = os.path.abspath(mtt.makeTempDir("memory1")) random.shuffle(g_nonTargetBlocks) random.shuffle(shuffledTargets) shuffledBlocks = list(shuffledTargets) lower = 0 for j in xrange(0, len(g_nonTargetBlocks)): # randomly insert the non target blocks, but keep a record # of their relative order. index = random.randint(lower, len(shuffledBlocks)) shuffledBlocks.insert(index, g_nonTargetBlocks[j]) lower = index + 1 testMaf = mtt.testFile( os.path.abspath(os.path.join(tmpDir, "test.maf")), "".join(shuffledBlocks), g_headers ) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd.append(os.path.abspath(os.path.join(parent, "test", "mafSorter"))) cmd += ["--maf", os.path.abspath(os.path.join(tmpDir, "test.maf")), "--seq", "hg18.chr7"] outpipes = [os.path.abspath(os.path.join(tmpDir, "sorted.maf"))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, "valgrind.xml"))) mtt.removeDir(tmpDir)
def testCoercion(self): """ mafStrander should coerce blocks into strandedness based on user input """ mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('coercion')) customOpts = mafval.GenericValidationOptions() for a, expected, strand in g_blocks: testMaf = mtt.testFile( os.path.abspath(os.path.join(tmpDir, 'test.maf')), ''.join(a), g_headers) parent = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) cmd = [ os.path.abspath(os.path.join(parent, 'test', 'mafStrander')), '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--seq', 'target.chr0', '--strand', strand ] outpipes = [os.path.abspath(os.path.join(tmpDir, 'coerced.maf'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue( mafIsCoerced(os.path.join(tmpDir, 'coerced.maf'), expected)) self.assertTrue( mafval.validateMaf(os.path.join(tmpDir, 'coerced.maf'), customOpts)) mtt.removeDir(tmpDir)
def testMemory1(self): """ If valgrind is installed on the system, check for memory related errors (1). """ mtt.makeTempDirParent() valgrind = mtt.which('valgrind') if valgrind is None: return tmpDir = os.path.abspath(mtt.makeTempDir('memeory1')) customOpts = mafval.GenericValidationOptions() for a, expected, strand in g_blocks: testMaf = mtt.testFile( os.path.abspath(os.path.join(tmpDir, 'test.maf')), ''.join(a), g_headers) parent = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd += [ os.path.abspath(os.path.join(parent, 'test', 'mafStrander')), '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--seq', 'target', '--strand', strand ] outpipes = [os.path.abspath(os.path.join(tmpDir, 'coerced.maf'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue( mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))) self.assertTrue( mafval.validateMaf(os.path.join(tmpDir, 'coerced.maf'), customOpts)) mtt.removeDir(tmpDir)
def test_memory_1(self): """ mafComparator should be memory clean for seed testing examples """ valgrind = mtt.which('valgrind') if valgrind is None: return mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('memory_1')) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) for maf1, maf2 in knownValuesSeed: testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) cmd = mtt.genericValgrind(tmpDir) cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.join(tmpDir, 'output.xml'), '--samples=10', '--logLevel=critical'] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))) for i in xrange(0, 4): mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))) mtt.removeDir(tmpDir)
def testNonExtraction1(self): """ mafExtractor should not extract blocks when they do not match. """ customOpts = mafval.GenericValidationOptions() mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('nonExtraction_1')) block = '''a degree=4 s simChimp.chrA 15393341 348 + 53121445 ATATTGAGGAGCAGGATGGGTATAGAGGCCCTGACCCATTAATGTGTAAGCACTAGGCAGCTGGGAGATACCCCAGAGGGCGGGGTCACTGAATTCACTGGCCCACCACTGTAAATACATTCTAACCAGTGGGTTTAGGGCTCTGTGCATTAGAACCACTCTGAAGAAGTGTAACACACCACCTAGTGAGCTGCCGGGCCGCCAGCAACTTCTTTTTCCCACATGACCCATGCAAGCCCGTGATTTCTCCCTGGTACATGATATTTGGGATTCCAGGGACCTAATGGAGCATGCTATTCCTGTGTTAGTTATCACTTCGAAGGGGGTGCAAGAGTGTAAGTAATGGGT s simGorilla.chrA 15595743 348 + 53120926 ATATTGAGGAGCAGGATGGGTATAGAAGCCCTGACCCATTAATGTGTAAGCACTAGGCAGCTGGGAGATACTCCAGAGGGAGGGGTCACTGAATTCACTGGCCCACCACTGTAAATACATTCTAACCAGTGGGTTTAGGGCTCGGTGCATTAGAACCACCCTGAAGAAGTGTAACGCACCACCTAGTGAGCTGCCGGGCCGCCAGCAACTTCTTTTTCCCACATGACCCATGCATGCCCGTGATTTCTCCCTGGTACATGGTTTTTGGGATTCCAGGGACCTAATGGAGCATACTATTCCTGTGTTAGTTATCACTTCGAAGGGGGTGCGAGAGTGTAAGTAATGGGT s simHuman.chrA 36713600 348 - 53106993 ATATTGAGGAGCAGGATGGGTATAGAAGCCCTGACCTATTAATGTGTAAGCACTAGGCAGCTGGGCGATACCCCAGAGGGAGGGGTCACTGAATTCACTGGCCCACCACTGTAAATACATTCTAACCAGTGGGTTTAGGGCTCTGTGCATTAGAACCACCCTGAAGAAGAGTAACGCACCACCTAGTGAGCTGCCGGGCCGCCAGCAAGTTCTTTTTCCCACATGACCCATGCAAGCCCGTGATTTCTCCCTGGTACATGATATTTGGGATTCCAGGGACCTAATGGAGCATGCTATTCCTGTGTTAGTTATCACTTCGAAGGGGGTGCAAGAGTGTAAGTAATGGGT s simOrang.chrE 126390 348 + 37692687 ATTTTGAGGAGCAGGATGGGTATAGAAGCCCTGACCCATTAATGTGTGAGCTCTAGGCAGCTTGGAGATACTGCAGAGGGAGGGGTCACTGAATTCACTGGCCCACCACTGTAAATACATACTAACCGGTGGGTTTAGGGCTCTGTGCATTAGAACCACCCTGAGGAAGTGTAACGCACCACCTAGTGAGCTGCCGGGCCACCAGCAACTTCTTTTTCCCACATGACCCATGCAAGCCCGTGATTTCTCCCTGGTACATGATCTTTGGGATTCCAGGGACCTAATGGCGGATGCTATTCCTGTGTTAGTTATCACTTCGAAGGGGGCGCAAGAGTGTAAGTAATGGGT s target.chr0 36713600 348 - 53106993 ATATTGAGGAGCAGGATGGGTATAGAAGCCCTGACCTATTAATGTGTAAGCACTAGGCAGCTGGGCGATACCCCAGAGGGAGGGGTCACTGAATTCACTGGCCCACCACTGTAAATACATTCTAACCAGTGGGTTTAGGGCTCTGTGCATTAGAACCACCCTGAAGAAGAGTAACGCACCACCTAGTGAGCTGCCGGGCCGCCAGCAAGTTCTTTTTCCCACATGACCCATGCAAGCCCGTGATTTCTCCCTGGTACATGATATTTGGGATTCCAGGGACCTAATGGAGCATGCTATTCCTGTGTTAGTTATCACTTCGAAGGGGGTGCAAGAGTGTAAGTAATGGGT ''' testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test.maf')), block, g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafExtractor'))] cmd += ['--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--seq', 'simHuman.chrA', '--start', '%d' % 29953315, '--stop', '%d' % 29953315, '--soft'] outpipes = [os.path.abspath(os.path.join(tmpDir, 'extracted.maf'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mtt.mafIsEmpty(os.path.join(tmpDir, 'extracted.maf'), g_headers)) self.assertTrue(mafval.validateMaf(os.path.join(tmpDir, 'extracted.maf'), customOpts)) mtt.removeDir(tmpDir)
def test_legitSequencesFail(self): """ --legitSequences options should fail when sequence length numbers differ from input files """ mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('legitSequencesFail')) i = -1 for maf1, maf2, totalTrue, totalFalse in knownValues: i += 1 testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [] cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')), '--samples=1000', '--logLevel=critical', '--legitSequences=%s' % knownValuesLegitFail[i], ] mtt.recordCommands([cmd], tmpDir) passed = False try: # we supress the normal stderr output here for the sake of sparing users confusion mtt.runCommandsS([cmd], tmpDir, errPipes=[subprocess.PIPE]) except RuntimeError: passed = True self.assertTrue(passed) mtt.removeDir(tmpDir)
def test_validXmlOutput_(self): """ xml output file should be valid xml. """ mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('validateXmlOutput')) # test 1 maf1, maf2, totalTrue, totalFalse = knownValues[0] testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'outputVanilla.xml')), '--samples=1000', '--logLevel=critical', ] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) passed = validXml(os.path.abspath(os.path.join(tmpDir, 'outputVanilla.xml'))) self.assertTrue(passed) self.assertFalse(validXml(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')))) # test 2 maf1, maf2, bed, totalTrue, totalTrueInInterval = knownValuesBed[2] testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) testBed = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'bed.bed')), bed, ['']) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'outputBed.xml')), '--samples=1000', '--logLevel=critical', ] cmd += ['--bedFiles', os.path.abspath(os.path.join(tmpDir, 'bed.bed'))] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) passed = validXml(os.path.abspath(os.path.join(tmpDir, 'outputBed.xml'))) # test 3 maf1, maf2, totalTrue, totalFalse = knownValues[0] testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'outputWiggles.xml')), '--samples=1000', '--logLevel=critical', '--wigglePairs=A:B', 'wiggleBinLength=2' ] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) passed = validXml(os.path.abspath(os.path.join(tmpDir, 'outputWiggles.xml'))) self.assertTrue(passed) mtt.removeDir(tmpDir)
def test_numberOfPairsFail(self): """ --numberOfPairs options should fail for bad input values """ mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('numberOfPairsFail')) i = -1 for maf1, maf2, totalTrue, totalFalse in knownValues: i += 1 testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [] cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')), '--samples=1000', '--logLevel=critical', '--numberOfPairs=%s' % knownValuesNumberOfPairsFail[i], ] mtt.recordCommands([cmd], tmpDir) passed = False try: mtt.runCommandsS([cmd], tmpDir, errPipes=[subprocess.PIPE]) except RuntimeError: passed = True self.assertTrue(passed) mtt.removeDir(tmpDir)
def test_knownValues(self): """ mafComparator should return correct results for hand-calculable problems """ mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('knownValues')) i = -1 for maf1, maf2, totalTrue, totalFalse in knownValues: i += 1 testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')), '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')), '--samples=1000', '--logLevel=critical', ] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) passedTT = totalTrue == getAggregateResult(os.path.abspath(os.path.join(tmpDir, 'output.xml')), 'totalTrue') passedTF = totalFalse == getAggregateResult(os.path.abspath(os.path.join(tmpDir, 'output.xml')), 'totalFalse') if not (passedTT and passedTF): print 'knownValues Test failed on test %d' % i self.assertTrue(passedTT and passedTF) mtt.removeDir(tmpDir)
def testMemory1(self): """ If valgrind is installed on the system, check for memory related errors (1). """ mtt.makeTempDirParent() valgrind = mtt.which('valgrind') if valgrind is None: return tmpDir = os.path.abspath(mtt.makeTempDir('memory1')) customOpts = mafval.GenericValidationOptions() for reference, inMaf, inFaList, outFa, outMaf in g_knownData: testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test.maf')), ''.join(inMaf), g_headers) testFaNames = testFasta(os.path.abspath(tmpDir), inFaList) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafToFastaStitcher')), '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--seqs', testFaNames, '--breakpointPenalty', '6', '--interstitialSequence', '20', '--outMfa', os.path.abspath(os.path.join(tmpDir, 'out.fa')), '--outMaf', os.path.abspath(os.path.join(tmpDir, 'out.maf')),] if reference is not None: cmd += ['--reference', reference] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))) mtt.removeDir(tmpDir)
def testMemory1(self): """ If valgrind is installed on the system, check for memory related errors (1). """ mtt.makeTempDirParent() valgrind = mtt.which('valgrind') if valgrind is None: return global g_header customOpts = mafval.GenericValidationOptions() for i in xrange(0, len(g_blocks)): tmpDir = os.path.abspath(mtt.makeTempDir('memory1')) testMafPath, g_header = mtt.testFile( os.path.abspath(os.path.join(tmpDir, 'test.maf')), g_blocks[i][0], g_headers) parent = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd.append( os.path.abspath(os.path.join(parent, 'test', 'mafRowOrderer'))) cmd += ['--maf', testMafPath, '--order', '%s' % g_order] outpipes = [os.path.abspath(os.path.join(tmpDir, 'ordered.maf'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue( mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))) self.assertTrue( mafval.validateMaf(os.path.join(tmpDir, 'ordered.maf'), customOpts)) mtt.removeDir(tmpDir)
def testSorting(self): """ Blocks should be sorted by the start field of the target sequence, blocks that do not contain the target sequence should appear in the output at the start of the file, in the same order they appear in the input. """ mtt.makeTempDirParent() shuffledTargets = list(g_targetBlocks) for i in xrange(0, 200): tmpDir = os.path.abspath(mtt.makeTempDir("sorting")) random.shuffle(g_nonTargetBlocks) random.shuffle(shuffledTargets) shuffledBlocks = list(shuffledTargets) lower = 0 for j in xrange(0, len(g_nonTargetBlocks)): # randomly insert the non target blocks, but keep a record # of their relative order. index = random.randint(lower, len(shuffledBlocks)) shuffledBlocks.insert(index, g_nonTargetBlocks[j]) lower = index + 1 testMaf = mtt.testFile( os.path.abspath(os.path.join(tmpDir, "test.maf")), "".join(shuffledBlocks), g_headers ) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, "test", "mafSorter"))] cmd += ["--maf", os.path.abspath(os.path.join(tmpDir, "test.maf")), "--seq", "hg18.chr7"] outpipes = [os.path.abspath(os.path.join(tmpDir, "sorted.maf"))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mafIsSorted(os.path.join(tmpDir, "sorted.maf"))) mtt.removeDir(tmpDir)
def testFilter(self): """ mafBlockDuplicateFilter should filter out duplicates in blocks according to sequence similarity to the consensus. """ for i in xrange(0, 10): shuffledBlocks = [] expectedOutput = [] tmpDir = os.path.abspath(mtt.makeTempDir()) order = [1] * len(g_duplicateBlocks) + [0] * len(g_nonDuplicateBlocks) random.shuffle(order) random.shuffle(g_duplicateBlocks) random.shuffle(g_nonDuplicateBlocks) j, k = 0, 0 for dupBlock in order: if dupBlock: shuffledBlocks.append(g_duplicateBlocks[j][0]) expectedOutput.append(g_duplicateBlocks[j][1]) j += 1 else: shuffledBlocks.append(g_nonDuplicateBlocks[k]) expectedOutput.append(g_nonDuplicateBlocks[k]) k += 1 testMaf = mtt.testFile(os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')), ''.join(shuffledBlocks), g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafBlockDuplicateFilter')), '--maf', os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf'))] outpipes = [os.path.abspath(os.path.join(tmpDir, 'filtered.maf'))] mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mafIsFiltered(os.path.join(tmpDir, 'filtered.maf'), expectedOutput)) mtt.removeTempDir()
def _testMemory1(self): """ If valgrind is installed on the system, check for memory related errors (0). """ valgrind = mtt.which('valgrind') if valgrind is None: return mtt.makeTempDirParent() for i in xrange(0, 10): shuffledBlocks = [] tmpDir = os.path.abspath(mtt.makeTempDir('memory_1')) order = [1] * len(g_overlappingBlocks) + [0] * len(g_nonOverlappingBlocks) random.shuffle(order) random.shuffle(g_overlappingBlocks) random.shuffle(g_nonOverlappingBlocks) j, k = 0, 0 for isOverlapping in order: if isOverlapping: shuffledBlocks.append(g_overlappingBlocks[j][0]) j += 1 else: shuffledBlocks.append(g_nonOverlappingBlocks[k][0]) k += 1 testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), ''.join(shuffledBlocks), g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd.append(os.path.abspath(os.path.join(parent, 'test', 'mafPairCoverage'))) cmd += ['--maf', os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), '--seq1', 'target.*', '--seq2', g_targetSeq2, ] outpipes = [os.path.join('/dev', 'null')] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))) mtt.removeDir(tmpDir)
def testCoverageBed_0(self): """ mafPairCoverage should be able to get the correct output given bed-based region intervals """ mtt.makeTempDirParent() for i in xrange(0, 10): shuffledBlocks = [] tmpDir = os.path.abspath(mtt.makeTempDir('bed_0')) order = [1] * len(g_overlappingBlocks) + [0] * len(g_nonOverlappingBlocks) random.shuffle(order) random.shuffle(g_overlappingBlocks) random.shuffle(g_nonOverlappingBlocks) j, k = 0, 0 total = 0 for isOverlapping in order: if isOverlapping: shuffledBlocks.append(g_overlappingBlocks[j][0]) total += g_overlappingBlocks[j][1] j += 1 else: shuffledBlocks.append(g_nonOverlappingBlocks[k][0]) k += 1 testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), ''.join(shuffledBlocks), g_headers) testBed = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'intervals.bed')), g_bedString) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafPairCoverage'))] cmd += ['--maf', os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), '--seq1', 'target.*', '--seq2', g_targetSeq2, '--bed', os.path.abspath(os.path.join(tmpDir, 'intervals.bed')) ] outpipes = [os.path.abspath(os.path.join(tmpDir, 'coverage.txt'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(coverageIsCorrect(os.path.join(tmpDir, 'coverage.txt'), g_coverageLinesWildBed)) mtt.removeDir(tmpDir)
def testExtraction(self): """ mafExtractor should output blocks that meet the criteria for extraction. That is they contain the target sequence and have at least one base in the target range. """ mtt.makeTempDirParent() customOpts = mafval.GenericValidationOptions() for i in xrange(0, 10): shuffledBlocks = [] tmpDir = os.path.abspath(mtt.makeTempDir('extraction')) order = [1] * len(g_overlappingBlocks) + [0] * len(g_nonOverlappingBlocks) random.shuffle(order) random.shuffle(g_overlappingBlocks) random.shuffle(g_nonOverlappingBlocks) j, k = 0, 0 for isOverlapping in order: if isOverlapping: shuffledBlocks.append(g_overlappingBlocks[j]) j += 1 else: shuffledBlocks.append(g_nonOverlappingBlocks[k]) k += 1 testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), ''.join(shuffledBlocks), g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafExtractor'))] cmd += ['--maf', os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), '--seq', g_targetSeq, '--start', '%d' % g_targetRange[0], '--stop', '%d' % g_targetRange[1], '--soft' ] outpipes = [os.path.abspath(os.path.join(tmpDir, 'extracted.maf'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(mafIsExtracted(os.path.join(tmpDir, 'extracted.maf'))) self.assertTrue(mafval.validateMaf(os.path.join(tmpDir, 'extracted.maf'), customOpts)) mtt.removeDir(tmpDir)
def testMemory_3(self): """ mafTransitiveClosure should be memory clean. """ mtt.makeTempDirParent() valgrind = mtt.which('valgrind') if valgrind is None: return tmpDir = os.path.abspath(mtt.makeTempDir('memory_3')) for inMaf, outList in self.knownResults: testMaf = mtt.testFile( os.path.abspath(os.path.join(tmpDir, 'test.maf')), inMaf, g_headers) parent = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) cmd = mtt.genericValgrind(tmpDir) cmd += [ os.path.abspath( os.path.join(parent, 'test', 'mafTransitiveClosure')), '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--sort' ] outpipes = [ os.path.abspath(os.path.join(tmpDir, 'transitiveClosure.maf')) ] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')) self.assertTrue(passed) mtt.removeDir(tmpDir)
def testCoverage_1(self): """ mafPairCoverage should output numbers that accurately reflect the coverage between sequences. """ mtt.makeTempDirParent() for i in xrange(0, 10): shuffledBlocks = [] tmpDir = os.path.abspath(mtt.makeTempDir('coverage_1')) order = [1] * len(g_overlappingBlocks) + [0] * len(g_nonOverlappingBlocks) random.shuffle(order) random.shuffle(g_overlappingBlocks) random.shuffle(g_nonOverlappingBlocks) j, k = 0, 0 total = 0 for isOverlapping in order: if isOverlapping: shuffledBlocks.append(g_overlappingBlocks[j][0]) total += g_overlappingBlocks[j][1] j += 1 else: shuffledBlocks.append(g_nonOverlappingBlocks[k][0]) k += 1 testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), ''.join(shuffledBlocks), g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafPairCoverage'))] cmd += ['--maf', os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)), '--seq1', 'target.*', '--seq2', g_targetSeq2, ] outpipes = [os.path.abspath(os.path.join(tmpDir, 'coverage.txt'))] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) self.assertTrue(coverageIsCorrect(os.path.join(tmpDir, 'coverage.txt'), g_coverageLinesWild)) mtt.removeDir(tmpDir)
def testKnownInOut_2(self): """ mafTransitiveClosure should compute the transitive closure of a maf built by pairwise alignment to a reference sequence, testing the --sort option. """ mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir('knownInOut_2')) for inMaf, outList in self.knownResults: testMaf = mtt.testFile( os.path.abspath(os.path.join(tmpDir, 'test.maf')), inMaf, g_headers) parent = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) cmd = [ os.path.abspath( os.path.join(parent, 'test', 'mafTransitiveClosure')), '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--sort' ] outpipes = [ os.path.abspath(os.path.join(tmpDir, 'transitiveClosure.maf')) ] mtt.recordCommands([cmd], tmpDir, outPipes=outpipes) mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes) passed = mafIsClosed(os.path.join(tmpDir, 'transitiveClosure.maf'), outList) self.assertTrue(passed) mtt.removeDir(tmpDir)
def test_coalescences_knownValues_withAncestors(self): """Test phylogeny comparison using coalescences, on MAFs that only have alignments for ancestors and leaves.""" mtt.makeTempDirParent() tmpDir = os.path.abspath(mtt.makeTempDir("coalescencesWithAncestors")) for i, (maf1, maf2, earlyCoalescences, lateCoalescences, identicalCoalescences) in enumerate(knownValues): testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), maf1, g_headers) testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), maf2, g_headers) parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafPhyloComparator')), '--mafFile1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), '--mafFile2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')), '--numSamples=10000', '--logLevel=critical', "--speciesTree=%s" % g_speciesTree, ] mtt.recordCommands([cmd], tmpDir) mtt.runCommandsS([cmd], tmpDir) outputFile = os.path.abspath(os.path.join(tmpDir, 'output.xml')) self.assertEqual(getAggregateCoalescenceResult(outputFile, 'earlyCoalescences'), earlyCoalescences, "early coalescences don't match on test %d" % (i + 1)) self.assertEqual(getAggregateCoalescenceResult(outputFile, 'lateCoalescences'), lateCoalescences, "late coalescences don't match on test %d" % (i + 1)) self.assertEqual(getAggregateCoalescenceResult(outputFile, 'identicalCoalescences'), identicalCoalescences, "identical coalescences don't match on test %d" % (i + 1)) mtt.removeDir(tmpDir)
def testDuplicateColumns(self): """ mafValidator should fail when a column is duplicated """ tmpDir = mtt.makeTempDir('duplicateColumns') for g in self.badMafs: mafFile, header = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test.maf')), g, g_headers) self.assertRaises(mafval.DuplicateColumnError, mafval.validateMaf, mafFile, options) mtt.removeDir(tmpDir)
def testELines(self): """mafValidator should fail when "e" lines are malformed """ tmpDir = mtt.makeTempDir('eLines') for b in self.badBlocks: mafFile, header = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test.maf')), b, g_headers) self.assertRaises(mafval.ELineFormatError, mafval.validateMaf, mafFile, options) mtt.removeDir(tmpDir)
def testSequenceRanges(self): """mafValidator should fail when sequences ranges go outside of source length """ tmpDir = mtt.makeTempDir('sequenceRanges') for i, b in enumerate(self.badRanges, 0): mafFile, header = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test.maf')), b, g_headers) self.assertRaises(mafval.OutOfRangeError, mafval.validateMaf, mafFile, options) mtt.removeDir(tmpDir)