-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1365 from pavanvidem/pytest-bamPEFragmentSize
Pytest bam pe fragment size
- Loading branch information
Showing
4 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import deeptools.bamPEFragmentSize | ||
from matplotlib.testing.compare import compare_images | ||
import os.path | ||
import filecmp | ||
from os import unlink | ||
from tempfile import NamedTemporaryFile | ||
|
||
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/test_data" | ||
|
||
|
||
def test_bamPEFragmentSize_histogram(): | ||
""" | ||
Test histogram plot for bamPEFragmentSize | ||
""" | ||
outfile = '/tmp/test_histogram.png' | ||
args = "--bamfiles {}/bowtie2_test1.bam --samplesLabel bowtie2_test1.bam --plotFileFormat png --plotTitle Test-Plot --histogram {}".format(ROOT, outfile).split() | ||
deeptools.bamPEFragmentSize.main(args) | ||
|
||
res = compare_images(ROOT + '/bamPEFragmentSize_histogram_result1.png', outfile, 10) | ||
assert res is None, res | ||
unlink(outfile) | ||
|
||
def test_bamPEFragmentSize_fr_sizes(): | ||
""" | ||
Test fragment length information for bamPEFragmentSize | ||
""" | ||
out_lengths = '/tmp/test_raw_frag_lengths.txt' | ||
out_metrics = '/tmp/test_metrics_table.txt' | ||
args = "--bamfiles {}/bowtie2_test1.bam --outRawFragmentLengths {} --table {}".format(ROOT, out_lengths, out_metrics).split() | ||
deeptools.bamPEFragmentSize.main(args) | ||
|
||
l = open(out_lengths, 'r') | ||
l_resp = l.readlines() | ||
l.close() | ||
l_expected = ['241\t1', '242\t1', '251\t1'] | ||
matches = [expected for expected in l_expected if any(expected in resp for resp in l_resp)] | ||
assert matches == l_expected | ||
|
||
m = open(out_metrics, 'r') | ||
m_resp = m.readlines()[1] | ||
m.close() | ||
m_expected = '3\t241.0\t241.5\t244.66666666666666\t242.0\t246.5\t251.0\t4.496912521077347\t1.0\t241.2\t241.4\t241.6\t241.8\t243.8\t245.6\t247.4\t249.2\t250.82\t3\t251.0\t251.0\t251.0\t251.0\t251.0\t251.0\t0.0\t0.0\t251.0\t251.0\t251.0\t251.0\t251.0\t251.0\t251.0\t251.0\t251.0\n' | ||
assert m_expected in f"{m_resp}" | ||
unlink(out_lengths) | ||
unlink(out_metrics) |
Binary file added
BIN
+16.2 KB
pydeeptools/deeptools/test/test_data/bamPEFragmentSize_histogram_result1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.