Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fidelram committed Jun 28, 2017
1 parent 6571f10 commit 33c3a55
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 26 deletions.
8 changes: 5 additions & 3 deletions hicexplorer/hicBuildMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,14 @@ def check_dangling_end(read, dangling_sequences):
ds = dangling_sequences
# skip forward read that stars with the restriction sequence
if not read.is_reverse and \
read.seq.upper()[0:len(ds['pat_forw'])] == ds['pat_forw']:
read.seq.upper().starswidth(ds['pat_forw']):
# read.seq.upper()[0:len(ds['pat_forw'])] == ds['pat_forw']:
return True

# skip reverse read that ends with the restriction sequence
if read.is_reverse and \
read.seq.upper()[-len(ds['pat_rev']):] == ds['pat_rev']:
read.seq.upper().endswidth(ds['pat_rev']):
# read.seq.upper()[-len(ds['pat_rev']):] == ds['pat_rev']:
return True

return False
Expand Down Expand Up @@ -1059,7 +1061,7 @@ def main(args=None):
args.restrictionSequence = args.restrictionSequence.upper()
args.danglingSequence = args.danglingSequence.upper()
dangling_sequences['pat_forw'] = args.danglingSequence
dangling_sequences['pat_rev'] = str(Seq(args.danglingSequence, generic_dna).complement())
dangling_sequences['pat_rev'] = str(Seq(args.danglingSequence, generic_dna).reverse_complement())

sys.stderr.write("dangling sequences to check "
"are {}\n".format(dangling_sequences))
Expand Down
18 changes: 15 additions & 3 deletions hicexplorer/test/test_buildMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from hicexplorer import HiCMatrix as hm
from tempfile import NamedTemporaryFile, mkdtemp
import shutil
import filecmp
import os
import numpy.testing as nt

Expand All @@ -13,11 +12,23 @@
dpnii_file = ROOT + "DpnII.bed"


def are_files_equal(file1, file2):
equal = True
with open(file1) as textfile1, open(file2) as textfile2:
for x, y in zip(textfile1, textfile2):
if x.startswith('File'):
continue
if x != y:
equal = False
break
return equal


def test_build_matrix():
outfile = NamedTemporaryFile(suffix='.h5', delete=False)
outfile.close()
qc_folder = mkdtemp(prefix="testQC_")
args = "-s {} {} -o {} -bs 5000 -b /tmp/test.bam --QCfolder {}".format(sam_R1, sam_R2,
args = "-s {} {} -o {} -bs 5000 -b /tmp/test.bam --QCfolder {} --threads 4".format(sam_R1, sam_R2,
outfile.name,
qc_folder).split()
hicBuildMatrix.main(args)
Expand All @@ -28,7 +39,7 @@ def test_build_matrix():
nt.assert_equal(test.cut_intervals, new.cut_intervals)

print set(os.listdir(ROOT + "QC/"))
filecmp(ROOT + "QC/QC.log", qc_folder + "/QC.log")
assert are_files_equal(ROOT + "QC/QC.log", qc_folder + "/QC.log")
assert set(os.listdir(ROOT + "QC/")) == set(os.listdir(qc_folder))

os.unlink(outfile.name)
Expand All @@ -54,6 +65,7 @@ def test_build_matrix_rf():
nt.assert_equal(test.cut_intervals, new.cut_intervals)

print set(os.listdir(ROOT + "QC_rc/"))
assert are_files_equal(ROOT + "QC_rc/QC.log", qc_folder + "/QC.log")
assert set(os.listdir(ROOT + "QC_rc/")) == set(os.listdir(qc_folder))

os.unlink(outfile.name)
Expand Down
22 changes: 11 additions & 11 deletions hicexplorer/test/test_data/QC_rc/QC.log
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ Pairs considered 99983
Min rest. site distance 150
Max rest. site distance 1500

Pairs used 36576 (36.58) (40.10)
Pairs used 36552 (36.56) (40.08)
One mate unmapped 8777 (8.78) (9.62)
One mate not unique 3603 (3.60) (3.95)
One mate low quality 34877 (34.88) (38.24)
dangling end 190 (0.19) (0.21)
self ligation (removed) 5061 (5.06) (5.55)
dangling end 209 (0.21) (0.23)
self ligation (removed) 5056 (5.06) (5.54)
One mate not close to rest site 751 (0.75) (0.82)
same fragment (800 bp) 10136 (10.14) (11.11)
same fragment (800 bp) 10146 (10.15) (11.12)
self circle 4274 (4.27) (4.69)
duplicated pairs 12 (0.01) (0.01)
Of pairs used:
inter chromosomal 5849 (15.99)
short range < 20kb 8694 (23.77)
long range 22033 (60.24)
inward pairs 6993 (19.12)
outward pairs 9525 (26.04)
left pairs 7020 (19.19)
right pairs 7189 (19.65)
inter chromosomal 5849 (16.00)
short range < 20kb 8689 (23.77)
long range 22014 (60.23)
inward pairs 6977 (19.09)
outward pairs 9525 (26.06)
left pairs 7012 (19.18)
right pairs 7189 (19.67)
Binary file modified hicexplorer/test/test_data/QC_rc/distance.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions hicexplorer/test/test_data/QC_rc/hicQC.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ <h2 id="table">Number of reads table</h2>
</tr>
<tr>
<th>Pairs used</th>
<td>36576</td>
<td>36552</td>
</tr>
<tr>
<th>dangling end</th>
<td>190</td>
<td>209</td>
</tr>
<tr>
<th>duplicated pairs</th>
Expand All @@ -147,15 +147,15 @@ <h2 id="table">Number of reads table</h2>
</tr>
<tr>
<th>inward pairs</th>
<td>6993</td>
<td>6977</td>
</tr>
<tr>
<th>left pairs</th>
<td>7020</td>
<td>7012</td>
</tr>
<tr>
<th>long range</th>
<td>22033</td>
<td>22014</td>
</tr>
<tr>
<th>outward pairs</th>
Expand All @@ -167,19 +167,19 @@ <h2 id="table">Number of reads table</h2>
</tr>
<tr>
<th>same fragment (800 bp)</th>
<td>10136</td>
<td>10146</td>
</tr>
<tr>
<th>self circle</th>
<td>4274</td>
</tr>
<tr>
<th>self ligation (removed)</th>
<td>5061</td>
<td>5056</td>
</tr>
<tr>
<th>short range &lt; 20kb</th>
<td>8694</td>
<td>8689</td>
</tr>
</tbody>
</table>
Expand Down
Binary file modified hicexplorer/test/test_data/QC_rc/pairs_considered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hicexplorer/test/test_data/QC_rc/pairs_used.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hicexplorer/test/test_data/QC_rc/read_orientation.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion hicexplorer/test/test_data/QC_rc/table.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
File Max rest. site distance Min rest. site distance One mate low quality One mate not close to rest site One mate not unique One mate unmapped Pairs considered Pairs used dangling end duplicated pairs inter chromosomal inward pairs left pairs long range outward pairs right pairs same fragment (800 bp) self circle self ligation (removed) short range < 20kb
small_test_rf_matrix.h5 1500 150 34877 751 3603 8777 99983 36576 190 12 5849 6993 7020 22033 9525 7189 10136 4274 5061 8694
small_test_rf_matrix.h5 1500 150 34877 751 3603 8777 99983 36552 209 12 5849 6977 7012 22014 9525 7189 10146 4274 5056 8689
Binary file not shown.

0 comments on commit 33c3a55

Please sign in to comment.