-
Notifications
You must be signed in to change notification settings - Fork 27
/
test_pacbio.py
109 lines (79 loc) · 2.59 KB
/
test_pacbio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from easydev import TempFile
from sequana.pacbio import BAMSimul, Barcoding, PacbioSubreads, PBSim
# DO NOT USE TEST DIR FOR NOW. This is used in the examples
from . import test_dir
def test_pacbio():
filename = f"{test_dir}/data/bam/test_pacbio_subreads.bam"
b = PacbioSubreads(filename)
assert len(b) == 130
b.df
# assert b.nb_pass[1] == 130
with TempFile() as fh:
b.filter_length(fh.name, threshold_min=500)
print(b) # check length
assert b.stats["mean_GC"] > 62.46
assert b.stats["mean_GC"] < 65.47
b.summary()
filename = f"{test_dir}/data/bam/test_pacbio_subreads.bam"
b = PacbioSubreads(filename)
# test hist_snr from scratch
b._df = None
b.hist_snr()
# test hist_len from scratch
b._df = None
b.hist_read_length()
b.hist_nb_passes()
b.get_mean_nb_passes()
# test from scratch
b._df = None
b.hist_GC()
# test from scratch
b._df = None
b.plot_GC_read_len()
# test from scratch
b._df = None
with TempFile() as fh:
b.to_fasta(fh.name, threads=1)
with TempFile() as fh:
b.to_fastq(fh.name, threads=1)
with TempFile() as fh:
b.save_summary(fh.name)
def test_pacbio_stride():
filename = f"{test_dir}/data/bam/test_pacbio_subreads.bam"
b = PacbioSubreads(filename)
with TempFile() as fh:
b.stride(fh.name, stride=2)
with TempFile() as fh:
b.stride(fh.name, stride=2, random=True)
def test_pacbio_random():
filename = f"{test_dir}/data/bam/test_pacbio_subreads.bam"
b = PacbioSubreads(filename)
with TempFile() as fh:
b.random_selection(fh.name, nreads=10)
with TempFile() as fh:
b.random_selection(fh.name, expected_coverage=10, reference_length=10000)
def test_bamsim():
filename = f"{test_dir}/data/bam/test_pacbio_subreads.bam"
b = BAMSimul(filename)
b.df
b.hist_read_length()
b.hist_GC()
b.plot_GC_read_len()
with TempFile() as fh:
b.filter_length(fh.name, threshold_min=500)
with TempFile() as fh:
mask = [True for this in range(len(b))]
b.filter_bool(fh.name, mask)
def test_pbsim():
filename = f"{test_dir}/data/bam/test_pacbio_subreads.bam"
ss = PBSim(filename, filename)
with TempFile() as fh:
ss.run(bins=100, step=50, output_filename=fh.name)
from pylab import close
close()
def test_barcoding():
data = f"{test_dir}/data/csv/test_pacbio_barcode_report.csv"
bc = Barcoding(data)
import tempfile
with tempfile.TemporaryDirectory() as tempdir:
bc.plot_and_save_all(directory=tempdir)