Skip to content

Commit

Permalink
clean up some tests, fix samtools read count
Browse files Browse the repository at this point in the history
  • Loading branch information
dpark01 committed Dec 3, 2014
1 parent 24f2655 commit 09847fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions test/test_read_utils.py
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.'
Expand Down
2 changes: 1 addition & 1 deletion tools/samtools.py
Expand Up @@ -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())

0 comments on commit 09847fb

Please sign in to comment.