diff --git a/test/test_read_utils.py b/test/test_read_utils.py index 545ffabde..4250f8f66 100644 --- a/test/test_read_utils.py +++ b/test/test_read_utils.py @@ -8,7 +8,6 @@ class TestPurgeUnmated(TestCaseWithTmp) : def test_purge_unmated(self) : - tempDir = tempfile.mkdtemp() myInputDir = util.file.get_test_input_path(self) inFastq1 = os.path.join(myInputDir, 'in1.fastq') inFastq2 = os.path.join(myInputDir, 'in2.fastq') @@ -26,7 +25,6 @@ def test_purge_unmated(self) : class TestFastqToFasta(TestCaseWithTmp) : def test_fastq_to_fasta(self) : - tempDir = tempfile.mkdtemp() myInputDir = util.file.get_test_input_path(self) inFastq = os.path.join(myInputDir, 'in.fastq') outFasta = util.file.mkstempfname('.fasta') @@ -41,7 +39,6 @@ def test_fastq_to_fasta(self) : class TestFastqBam(TestCaseWithTmp) : 'Class for testing fastq <-> bam conversions' def test_fastq_bam(self) : - tempDir = tempfile.mkdtemp() myInputDir = util.file.get_test_input_path(self) # Define file names @@ -70,10 +67,8 @@ def test_fastq_bam(self) : read_utils.main_fastq_to_bam(args) # samtools view for out.sam and compare to expected - samtoolsPath = tools.samtools.SamtoolsTool().install_and_get_path() - viewCmd = '{samtoolsPath} view -h {outBamCmd} > {outSam}'.format( - **locals()) - assert not os.system(viewCmd) + samtools = tools.samtools.SamtoolsTool() + samtools.execute('view', ['-h', outBamCmd], stdout=outSam) assert_equal_contents(self, outSam, expectedSam) # in1.fastq, in2.fastq, inHeader.txt -> out.bam; header from txt @@ -95,6 +90,12 @@ def test_fastq_bam(self) : assert_equal_contents(self, outFastq1, expectedFastq1) # 1 base trimmed assert_equal_contents(self, outFastq2, inFastq2) assert_equal_contents(self, outHeader, inHeader) + + def test_bam_count(self): + expectedSam = os.path.join(util.file.get_test_input_path(self), 'expected.sam') + n = tools.samtools.SamtoolsTool().count(expectedSam, ['-S']) + self.assertEqual(n, 2) + class TestSplitReads(TestCaseWithTmp) : 'Test various options of split_reads command.' diff --git a/tools/samtools.py b/tools/samtools.py index f3e713ec1..6d91bccf5 100644 --- a/tools/samtools.py +++ b/tools/samtools.py @@ -48,6 +48,6 @@ def dumpHeader(self, inBam, outHeader) : def count(self, inBam, opts=[]) : tmp = util.file.mkstempfname('.count') - self.execute('view', ['-c'] + opts, stdout=tmp) + self.execute('view', ['-c'] + opts + [inBam], stdout=tmp) with open(tmp, 'rt') as inf: return int(inf.readline().strip())