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 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()
Example #3
0
 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.
     """
     shuffledTargets = list(g_targetBlocks)
     for i in xrange(0, 100):
         tmpDir = os.path.abspath(mtt.makeTempDir())
         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(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", "mafBlockSorter"))]
         cmd += ["--maf", os.path.abspath(os.path.join(os.curdir, "tempTestDir", "test.maf")), "--seq", "hg18.chr7"]
         outpipes = [os.path.abspath(os.path.join(tmpDir, "sorted.maf"))]
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mafIsSorted(os.path.join(tmpDir, "sorted.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 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()
Example #6
0
 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()
Example #7
0
 def testMemory(self):
     """ sharedMaf.h should be memory clean.
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     tmpDir = os.path.abspath(mtt.makeTempDir())
     cmd = [valgrind, '--leak-check=full', '--track-origins=yes', 
            '--show-reachable=yes', '--xml=yes', 
            '--xml-file=' + os.path.join(tmpDir, 'valgrind.xml')]
     cmd.append(os.path.abspath(os.path.join(os.curdir, 'allTests')))
     mtt.runCommandsS([cmd], tmpDir)
     self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
     mtt.removeTempDir()
 def testNonFilter(self):
     """ mafBlockDuplicateFilter should not filter out any sequences from blocks when there are no duplicates.
     """
     for i in xrange(0, 10):
         tmpDir = os.path.abspath(mtt.makeTempDir())
         random.shuffle(g_nonDuplicateBlocks)
         testMaf = mtt.testFile(os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')),
                                ''.join(g_nonDuplicateBlocks), g_headers)
         expectedOutput = g_nonDuplicateBlocks
         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 testNonExtraction(self):
     """ mafBlockExtractor should not extract blocks when they do not match.
     """
     for i in xrange(0, 10):
         tmpDir = os.path.abspath(mtt.makeTempDir())
         random.shuffle(g_nonOverlappingBlocks)
         testMaf = mtt.testFile(os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')),
                                ''.join(g_nonOverlappingBlocks), 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(mtt.fileIsEmpty(os.path.join(tmpDir, 'extracted.maf')))
         mtt.removeTempDir()
Example #10
0
 def dtestNonFind(self):
     """ mafBlockFinder should not report any lines when blocks do not match.
     """
     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 = [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.fileIsEmpty(os.path.join(tmpDir, "found.txt")))
         mtt.removeTempDir()
Example #11
0
 def testFind(self):
     """ mafBlockFinder should report information about matching sequences within blocks.
     """
     global g_header
     for i in xrange(0, len(g_overlappingBlocks)):
         tmpDir = os.path.abspath(mtt.makeTempDir())
         testMafPath, g_header = mtt.testFile(
             os.path.abspath(os.path.join(os.curdir, "tempTestDir", "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", "mafBlockFinder"))]
         cmd += ["--maf", testMafPath, "--seq", g_targetSeq, "--pos", "%d" % g_overlappingBlocks[i][1]]
         outpipes = [os.path.abspath(os.path.join(tmpDir, "found.txt"))]
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(foundLines(g_overlappingBlocks[i][2], os.path.join(tmpDir, "found.txt"), g_header))
         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
     for i in xrange(0, 10):
         tmpDir = os.path.abspath(mtt.makeTempDir())
         random.shuffle(g_nonDuplicateBlocks)
         testMaf = mtt.testFile(os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')),
                                ''.join(g_nonDuplicateBlocks), g_headers)
         expectedOutput = g_nonDuplicateBlocks
         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()
Example #13
0
 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
     shuffledTargets = list(g_targetBlocks)
     for i in xrange(0, 20):
         tmpDir = os.path.abspath(mtt.makeTempDir())
         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(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", "mafBlockSorter")))
         cmd += ["--maf", os.path.abspath(os.path.join(os.curdir, "tempTestDir", "test.maf")), "--seq", "hg18.chr7"]
         outpipes = [os.path.abspath(os.path.join(tmpDir, "sorted.maf"))]
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, "valgrind.xml")))
         mtt.removeTempDir()