hicstuff 3.2.2__tar.gz → 3.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hicstuff-3.2.2/hicstuff.egg-info → hicstuff-3.2.3}/PKG-INFO +1 -1
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/commands.py +18 -3
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/main.py +1 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/pipeline.py +6 -1
- hicstuff-3.2.3/hicstuff/stats.py +185 -0
- hicstuff-3.2.3/hicstuff/version.py +1 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3/hicstuff.egg-info}/PKG-INFO +1 -1
- {hicstuff-3.2.2 → hicstuff-3.2.3}/setup.py +1 -1
- hicstuff-3.2.2/hicstuff/stats.py +0 -154
- hicstuff-3.2.2/hicstuff/version.py +0 -1
- {hicstuff-3.2.2 → hicstuff-3.2.3}/LICENSE +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/MANIFEST.in +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/README.md +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/__init__.py +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/cutsite.py +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/digest.py +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/distance_law.py +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/filter.py +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/hicstuff.py +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/io.py +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/iteralign.py +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/log.py +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff/view.py +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff.egg-info/SOURCES.txt +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff.egg-info/dependency_links.txt +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff.egg-info/entry_points.txt +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff.egg-info/requires.txt +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/hicstuff.egg-info/top_level.txt +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/requirements.txt +0 -0
- {hicstuff-3.2.2 → hicstuff-3.2.3}/setup.cfg +0 -0
|
@@ -14,9 +14,10 @@ commands:
|
|
|
14
14
|
-view (map visualization)
|
|
15
15
|
-pipeline (whole contact map generation)
|
|
16
16
|
-distancelaw (Analysis tool and plot for the distance law)
|
|
17
|
+
-stats (Extract stats from log)
|
|
17
18
|
|
|
18
19
|
Running 'pipeline' implies running 'digest', but not
|
|
19
|
-
iteralign or filter unless specified, because they can
|
|
20
|
+
'iteralign' or 'filter' unless specified, because they can
|
|
20
21
|
take up a lot of time for dimnishing returns.
|
|
21
22
|
|
|
22
23
|
Note
|
|
@@ -38,7 +39,7 @@ ValueError
|
|
|
38
39
|
import re
|
|
39
40
|
import sys, os, shutil
|
|
40
41
|
import tempfile
|
|
41
|
-
from os.path import join, dirname
|
|
42
|
+
from os.path import join, dirname, basename
|
|
42
43
|
from matplotlib import pyplot as plt
|
|
43
44
|
from matplotlib import cm
|
|
44
45
|
from docopt import docopt
|
|
@@ -54,6 +55,7 @@ import hicstuff.cutsite as hcc
|
|
|
54
55
|
import hicstuff.digest as hcd
|
|
55
56
|
import hicstuff.iteralign as hci
|
|
56
57
|
import hicstuff.filter as hcf
|
|
58
|
+
import hicstuff.stats as hcs
|
|
57
59
|
from hicstuff.version import __version__
|
|
58
60
|
import hicstuff.io as hio
|
|
59
61
|
from hicstuff.log import logger
|
|
@@ -1656,6 +1658,20 @@ class Missview(AbstractCommand):
|
|
|
1656
1658
|
)
|
|
1657
1659
|
logger.info("Output image saved at %s.", out)
|
|
1658
1660
|
|
|
1661
|
+
class Stats(AbstractCommand):
|
|
1662
|
+
"""Extract stats from a hicstuff log file.
|
|
1663
|
+
|
|
1664
|
+
usage:
|
|
1665
|
+
stats <log>
|
|
1666
|
+
|
|
1667
|
+
arguments:
|
|
1668
|
+
log Path to a hicstuff log file.
|
|
1669
|
+
"""
|
|
1670
|
+
|
|
1671
|
+
def execute(self):
|
|
1672
|
+
log_file = self.args["<log>"]
|
|
1673
|
+
stats = hcs.get_pipeline_stats(log_file)
|
|
1674
|
+
hcs.print_pipeline_stats(stats)
|
|
1659
1675
|
|
|
1660
1676
|
def parse_bin_str(bin_str):
|
|
1661
1677
|
"""Bin string parsing
|
|
@@ -1696,7 +1712,6 @@ def parse_bin_str(bin_str):
|
|
|
1696
1712
|
|
|
1697
1713
|
return binning
|
|
1698
1714
|
|
|
1699
|
-
|
|
1700
1715
|
def parse_ucsc(ucsc_str, bins):
|
|
1701
1716
|
"""
|
|
1702
1717
|
Take a UCSC region in UCSC notation and a list of bin chromosomes and
|
|
@@ -21,6 +21,7 @@ The subcommands are:
|
|
|
21
21
|
iteralign Iteratively aligns reads to a reference genome.
|
|
22
22
|
missview Preview missing Hi-C bins in based on the genome and read length.
|
|
23
23
|
pipeline Hi-C pipeline to generate contact matrix from fastq files.
|
|
24
|
+
stats Extract mapping statistics from a hicstuff pipeline log file.
|
|
24
25
|
rebin Bin the matrix and regenerate files accordingly.
|
|
25
26
|
subsample Bootstrap subsampling of contacts from a Hi-C map.
|
|
26
27
|
view Visualize a Hi-C matrix.
|
|
@@ -26,6 +26,8 @@ import hicstuff.cutsite as hcc
|
|
|
26
26
|
import hicstuff.stats as hcs
|
|
27
27
|
import matplotlib
|
|
28
28
|
import pathlib
|
|
29
|
+
import pairtools
|
|
30
|
+
from packaging.version import Version
|
|
29
31
|
from hicstuff.version import __version__
|
|
30
32
|
import hicstuff.log as hcl
|
|
31
33
|
from hicstuff.log import logger
|
|
@@ -1140,7 +1142,8 @@ def full_pipeline(
|
|
|
1140
1142
|
# Get stats on the pipeline
|
|
1141
1143
|
try:
|
|
1142
1144
|
logger.info("Fetching mapping and pairing stats")
|
|
1143
|
-
hcs.get_pipeline_stats(
|
|
1145
|
+
stats = hcs.get_pipeline_stats(log_file)
|
|
1146
|
+
logger.info(stats)
|
|
1144
1147
|
except IndexError:
|
|
1145
1148
|
logger.warning("IndexError. Stats not compiled.")
|
|
1146
1149
|
pass
|
|
@@ -1156,6 +1159,8 @@ def full_pipeline(
|
|
|
1156
1159
|
sort_args = "--output {out} --tmpdir {tmp_dir}".format(
|
|
1157
1160
|
out = sorted_pairsf, tmp_dir = tmp_dir
|
|
1158
1161
|
)
|
|
1162
|
+
if (Version(pairtools.__version__) >= Version('1.1.0')):
|
|
1163
|
+
sort_args = sort_args + " --c1 chr1 --c2 chr2 --p1 pos1 --p2 pos2 --pt frag1"
|
|
1159
1164
|
sp.call(pairstools_cmd + sort_args.split(" ") + [pairsf], shell=False)
|
|
1160
1165
|
os.remove(pairsf)
|
|
1161
1166
|
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
import os
|
|
6
|
+
from os.path import basename
|
|
7
|
+
from os.path import splitext
|
|
8
|
+
import json
|
|
9
|
+
|
|
10
|
+
def get_pipeline_stats(log_file):
|
|
11
|
+
"""Get stats after pipeline execution.
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
log_file : str
|
|
16
|
+
Path to hicstuff log file.
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
list:
|
|
21
|
+
A single list containing stats about hicstuff pipeline execution:
|
|
22
|
+
- Number of sequenced pairs from fastqs
|
|
23
|
+
- Number (% of total reads) of unmapped reads
|
|
24
|
+
- Number (% of total reads) of mapped reads
|
|
25
|
+
- Number (% of total reads) of pairs
|
|
26
|
+
- Number (% of total pairs) of filtered pairs
|
|
27
|
+
- Number (% of total pairs) of loops
|
|
28
|
+
- Number (% of total pairs) of uncuts
|
|
29
|
+
- Number (% of total pairs) of abnormal (-- and ++)
|
|
30
|
+
- Number (% of total pairs) of deduplicated pairs [Number (% of total pairs) of PCR duplicates]
|
|
31
|
+
- From all pairs used in contact matrix:
|
|
32
|
+
- Number (% of matrix) of cis pairs
|
|
33
|
+
- Number (% of matrix) of trans pairs
|
|
34
|
+
- Trans ratio
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
with open(log_file) as file:
|
|
38
|
+
log_lines = [line.rstrip() for line in file]
|
|
39
|
+
|
|
40
|
+
# 1. Number of sequenced pairs from fastqs
|
|
41
|
+
fastq_pairs = [s for s in log_lines if re.search("reads found in each", s)][0]
|
|
42
|
+
fastq_pairs = re.sub(".*INFO :: ", "", fastq_pairs)
|
|
43
|
+
fastq_pairs = re.sub(" reads found in each.*", "", fastq_pairs)
|
|
44
|
+
fastq_pairs = int(float(fastq_pairs))
|
|
45
|
+
|
|
46
|
+
# 2. Number (% of total) of (un)mapped reads
|
|
47
|
+
tot_mapped = [s for s in log_lines if re.search("mapped with Q ", s)][0]
|
|
48
|
+
tot_mapped = re.sub(".*Q >= 30 \(", "", tot_mapped)
|
|
49
|
+
tot_mapped = re.sub("/.*", "", tot_mapped)
|
|
50
|
+
tot_mapped = int(float(tot_mapped))
|
|
51
|
+
tot_unmapped = fastq_pairs*2 - tot_mapped
|
|
52
|
+
|
|
53
|
+
# 3. Number (% of total) of pairs
|
|
54
|
+
tot_pairs = [s for s in log_lines if re.search("pairs successfully mapped", s)][0]
|
|
55
|
+
tot_pairs = re.sub(".*INFO :: ", "", tot_pairs)
|
|
56
|
+
tot_pairs = re.sub(" pairs successfully.*", "", tot_pairs)
|
|
57
|
+
tot_pairs = int(float(tot_pairs))
|
|
58
|
+
|
|
59
|
+
# 4. Number (% of total) of filtered pairs
|
|
60
|
+
filtered_pairs = [s for s in log_lines if re.search("pairs discarded:", s)]
|
|
61
|
+
if (len(filtered_pairs) > 0):
|
|
62
|
+
filtered_pairs = filtered_pairs[0]
|
|
63
|
+
loops_pairs = re.sub(".*Loops: ", "", filtered_pairs)
|
|
64
|
+
loops_pairs = re.sub(", Uncuts:.*", "", loops_pairs)
|
|
65
|
+
loops_pairs = int(float(loops_pairs))
|
|
66
|
+
uncuts_pairs = re.sub(".*Uncuts: ", "", filtered_pairs)
|
|
67
|
+
uncuts_pairs = re.sub(", Weirds:.*", "", uncuts_pairs)
|
|
68
|
+
uncuts_pairs = int(float(uncuts_pairs))
|
|
69
|
+
abnormal_pairs = re.sub(".*Weirds: ", "", filtered_pairs)
|
|
70
|
+
abnormal_pairs = int(float(abnormal_pairs))
|
|
71
|
+
filtered_pairs = re.sub(".*INFO :: ", "", filtered_pairs)
|
|
72
|
+
filtered_pairs = re.sub(" pairs discarded.*", "", filtered_pairs)
|
|
73
|
+
filtered_pairs = int(float(filtered_pairs))
|
|
74
|
+
else:
|
|
75
|
+
loops_pairs=0
|
|
76
|
+
uncuts_pairs=0
|
|
77
|
+
abnormal_pairs=0
|
|
78
|
+
filtered_pairs=0
|
|
79
|
+
|
|
80
|
+
# 5. Number (% of total) of PCR duplicates pairs
|
|
81
|
+
pcr_pairs = [s for s in log_lines if re.search("PCR duplicates have been filtered", s)]
|
|
82
|
+
if (len(pcr_pairs) > 0):
|
|
83
|
+
pcr_pairs = pcr_pairs[0]
|
|
84
|
+
pcr_pairs = re.sub(".*have been filtered out \(", "", pcr_pairs)
|
|
85
|
+
pcr_pairs = re.sub(" / .*", "", pcr_pairs)
|
|
86
|
+
pcr_pairs = int(float(pcr_pairs))
|
|
87
|
+
else:
|
|
88
|
+
pcr_pairs = 0
|
|
89
|
+
|
|
90
|
+
# 6. Number (%) of final pairs
|
|
91
|
+
removed_pairs=filtered_pairs+pcr_pairs
|
|
92
|
+
final_pairs=tot_pairs-removed_pairs
|
|
93
|
+
|
|
94
|
+
# 7. Final stats
|
|
95
|
+
stats = {
|
|
96
|
+
'Sample': re.sub(".hicstuff.*", "", basename(log_file)),
|
|
97
|
+
'Total read pairs': fastq_pairs,
|
|
98
|
+
'Mapped reads': tot_mapped,
|
|
99
|
+
'Unmapped reads': tot_unmapped,
|
|
100
|
+
'Recovered contacts': tot_pairs,
|
|
101
|
+
'Final contacts': final_pairs,
|
|
102
|
+
'Removed contacts': removed_pairs,
|
|
103
|
+
'Filtered out': filtered_pairs,
|
|
104
|
+
'Loops': loops_pairs,
|
|
105
|
+
'Uncuts': uncuts_pairs,
|
|
106
|
+
'Weirds': abnormal_pairs,
|
|
107
|
+
'PCR duplicates': pcr_pairs
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return(stats)
|
|
111
|
+
|
|
112
|
+
def write_pipeline_stats(stats, out_file):
|
|
113
|
+
prefix = stats['Sample']
|
|
114
|
+
fastq_pairs=stats['Total read pairs']
|
|
115
|
+
tot_mapped=stats['Mapped reads']
|
|
116
|
+
tot_unmapped=stats['Unmapped reads']
|
|
117
|
+
tot_pairs=stats['Recovered contacts']
|
|
118
|
+
final_pairs=stats['Final contacts']
|
|
119
|
+
removed_pairs=stats['Removed contacts']
|
|
120
|
+
filtered_pairs=stats['Filtered out']
|
|
121
|
+
loops_pairs=stats['Loops']
|
|
122
|
+
uncuts_pairs=stats['Uncuts']
|
|
123
|
+
abnormal_pairs=stats['Weirds']
|
|
124
|
+
pcr_pairs=stats['PCR duplicates']
|
|
125
|
+
pct_pairs = round(tot_pairs/fastq_pairs*100, 2)
|
|
126
|
+
pct_mapped = round(tot_mapped/(fastq_pairs*2)*100, 2)
|
|
127
|
+
pct_unmapped = round(tot_unmapped/(fastq_pairs*2)*100, 2)
|
|
128
|
+
pct_filtered = round(filtered_pairs/tot_pairs*100, 2)
|
|
129
|
+
pct_loops_pairs = round(loops_pairs/tot_pairs*100, 2)
|
|
130
|
+
pct_uncuts_pairs = round(uncuts_pairs/tot_pairs*100, 2)
|
|
131
|
+
pct_abnormal_pairs = round(abnormal_pairs/tot_pairs*100, 2)
|
|
132
|
+
pct_pcr = round(pcr_pairs/tot_pairs*100, 2)
|
|
133
|
+
pct_removed=round(removed_pairs/tot_pairs*100, 2)
|
|
134
|
+
pct_final = round(final_pairs/tot_pairs*100, 2)
|
|
135
|
+
|
|
136
|
+
# Open the log file and read its contents
|
|
137
|
+
_, file_extension = splitext(out_file)
|
|
138
|
+
if (file_extension == '.json'):
|
|
139
|
+
with open(out_file, 'w') as json_file:
|
|
140
|
+
json.dump(stats, json_file, indent=4)
|
|
141
|
+
else:
|
|
142
|
+
with open(out_file, 'w') as stats_file:
|
|
143
|
+
stats_file.write("Sample: {prefix}\n".format(prefix = prefix))
|
|
144
|
+
stats_file.write("Total read pairs: {reads}\n".format(reads = "{:,}".format(fastq_pairs)))
|
|
145
|
+
stats_file.write("Mapped reads: {tot_mapped} ({pct_mapped}% of all reads)\n".format(
|
|
146
|
+
tot_mapped = "{:,}".format(tot_mapped),
|
|
147
|
+
pct_mapped = pct_mapped
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
stats_file.write("Unmapped reads: {tot_unmapped} ({pct_unmapped}% of all reads)\n".format(
|
|
151
|
+
tot_unmapped = "{:,}".format(tot_unmapped), pct_unmapped = pct_unmapped
|
|
152
|
+
))
|
|
153
|
+
stats_file.write("Recovered contacts: {tot_pairs} ({pct_pairs}% of all read pairs)\n".format(
|
|
154
|
+
tot_pairs = "{:,}".format(tot_pairs), pct_pairs = pct_pairs
|
|
155
|
+
))
|
|
156
|
+
stats_file.write("Removed contacts: {removed_pairs} ({pct_removed}% of all contacts)\n".format(
|
|
157
|
+
removed_pairs = "{:,}".format(removed_pairs), pct_removed = pct_removed
|
|
158
|
+
))
|
|
159
|
+
stats_file.write(" Filtered out: {filtered_pairs} ({pct_filtered}% of all contacts)\n".format(
|
|
160
|
+
filtered_pairs = "{:,}".format(filtered_pairs), pct_filtered = pct_filtered
|
|
161
|
+
))
|
|
162
|
+
stats_file.write(" Loops: {loops_pairs} ({pct_loops_pairs}% of all contacts)\n".format(
|
|
163
|
+
loops_pairs = "{:,}".format(loops_pairs), pct_loops_pairs = pct_loops_pairs
|
|
164
|
+
))
|
|
165
|
+
stats_file.write(" Uncuts: {uncuts_pairs} ({pct_uncuts_pairs}% of all contacts)\n".format(
|
|
166
|
+
uncuts_pairs = "{:,}".format(uncuts_pairs), pct_uncuts_pairs = pct_uncuts_pairs
|
|
167
|
+
))
|
|
168
|
+
stats_file.write(" Weirds: {abnormal_pairs} ({pct_abnormal_pairs}% of all contacts)\n".format(
|
|
169
|
+
abnormal_pairs = "{:,}".format(abnormal_pairs), pct_abnormal_pairs = pct_abnormal_pairs
|
|
170
|
+
))
|
|
171
|
+
stats_file.write(" PCR duplicates: {pcr_pairs} ({pct_pcr}% of all contacts)\n".format(
|
|
172
|
+
pcr_pairs = "{:,}".format(pcr_pairs), pct_pcr = pct_pcr
|
|
173
|
+
))
|
|
174
|
+
stats_file.write("Final contacts: {final_pairs} ({pct_final}% of all contacts)\n".format(
|
|
175
|
+
final_pairs = "{:,}".format(final_pairs), pct_final = pct_final
|
|
176
|
+
))
|
|
177
|
+
|
|
178
|
+
def print_pipeline_stats(stats):
|
|
179
|
+
tmp = '.'+stats['Sample']+'.txt'
|
|
180
|
+
write_pipeline_stats(stats, tmp)
|
|
181
|
+
with open(tmp, 'r') as file:
|
|
182
|
+
lines = [line for line in file]
|
|
183
|
+
print(''.join(lines))
|
|
184
|
+
os.unlink(tmp)
|
|
185
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '3.2.3'
|
hicstuff-3.2.2/hicstuff/stats.py
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
|
|
4
|
-
import re
|
|
5
|
-
from os.path import join
|
|
6
|
-
import json
|
|
7
|
-
|
|
8
|
-
def get_pipeline_stats(prefix, out_dir, log_file):
|
|
9
|
-
"""Get stats after pipeline execution.
|
|
10
|
-
|
|
11
|
-
Parameters
|
|
12
|
-
----------
|
|
13
|
-
prefix : str
|
|
14
|
-
The prefix used to create output files by the pipeline.
|
|
15
|
-
out_dir : str
|
|
16
|
-
The prefix used to create output files by the pipeline.
|
|
17
|
-
log_file : str
|
|
18
|
-
Path to hicstuff log file.
|
|
19
|
-
|
|
20
|
-
Returns
|
|
21
|
-
-------
|
|
22
|
-
txt file:
|
|
23
|
-
A single text file containing stats about hicstuff pipeline execution:
|
|
24
|
-
- Number of sequenced pairs from fastqs
|
|
25
|
-
- Number (% of total reads) of unmapped reads
|
|
26
|
-
- Number (% of total reads) of mapped reads
|
|
27
|
-
- Number (% of total reads) of pairs
|
|
28
|
-
- Number (% of total pairs) of filtered pairs
|
|
29
|
-
- Number (% of total pairs) of loops
|
|
30
|
-
- Number (% of total pairs) of uncuts
|
|
31
|
-
- Number (% of total pairs) of abnormal (-- and ++)
|
|
32
|
-
- Number (% of total pairs) of deduplicated pairs [Number (% of total pairs) of PCR duplicates]
|
|
33
|
-
- From all pairs used in contact matrix:
|
|
34
|
-
- Number (% of matrix) of cis pairs
|
|
35
|
-
- Number (% of matrix) of trans pairs
|
|
36
|
-
- Trans ratio
|
|
37
|
-
"""
|
|
38
|
-
|
|
39
|
-
with open(log_file) as file:
|
|
40
|
-
log_lines = [line.rstrip() for line in file]
|
|
41
|
-
|
|
42
|
-
# 1. Number of sequenced pairs from fastqs
|
|
43
|
-
fastq_pairs = [s for s in log_lines if re.search("reads found in eajch fastq file.", s)][0]
|
|
44
|
-
fastq_pairs = re.sub(".*INFO :: ", "", fastq_pairs)
|
|
45
|
-
fastq_pairs = re.sub(" reads found in each fastq file.*", "", fastq_pairs)
|
|
46
|
-
fastq_pairs = int(float(fastq_pairs))
|
|
47
|
-
|
|
48
|
-
# 2. Number (% of total) of (un)mapped reads
|
|
49
|
-
tot_mapped = [s for s in log_lines if re.search("mapped with Q ", s)][0]
|
|
50
|
-
tot_mapped = re.sub(".*Q >= 30 \(", "", tot_mapped)
|
|
51
|
-
tot_mapped = re.sub("/.*", "", tot_mapped)
|
|
52
|
-
tot_mapped = int(float(tot_mapped))
|
|
53
|
-
tot_unmapped = fastq_pairs*2 - tot_mapped
|
|
54
|
-
pct_mapped = round(tot_mapped/(fastq_pairs*2)*100, 2)
|
|
55
|
-
pct_unmapped = round(tot_unmapped/(fastq_pairs*2)*100, 2)
|
|
56
|
-
|
|
57
|
-
# 3. Number (% of total) of pairs
|
|
58
|
-
tot_pairs = [s for s in log_lines if re.search("pairs successfully mapped", s)][0]
|
|
59
|
-
tot_pairs = re.sub(".*INFO :: ", "", tot_pairs)
|
|
60
|
-
tot_pairs = re.sub(" pairs successfully.*", "", tot_pairs)
|
|
61
|
-
tot_pairs = int(float(tot_pairs))
|
|
62
|
-
pct_pairs = round(tot_pairs/fastq_pairs*100, 2)
|
|
63
|
-
|
|
64
|
-
# 4. Number (% of total) of filtered pairs
|
|
65
|
-
filtered_pairs = [s for s in log_lines if re.search("pairs discarded:", s)]
|
|
66
|
-
if (len(filtered_pairs) > 0):
|
|
67
|
-
filtered_pairs = filtered_pairs[0]
|
|
68
|
-
loops_pairs = re.sub(".*Loops: ", "", filtered_pairs)
|
|
69
|
-
loops_pairs = re.sub(", Uncuts:.*", "", loops_pairs)
|
|
70
|
-
loops_pairs = int(float(loops_pairs))
|
|
71
|
-
uncuts_pairs = re.sub(".*Uncuts: ", "", filtered_pairs)
|
|
72
|
-
uncuts_pairs = re.sub(", Weirds:.*", "", uncuts_pairs)
|
|
73
|
-
uncuts_pairs = int(float(uncuts_pairs))
|
|
74
|
-
abnormal_pairs = re.sub(".*Weirds: ", "", filtered_pairs)
|
|
75
|
-
abnormal_pairs = int(float(abnormal_pairs))
|
|
76
|
-
filtered_pairs = re.sub(".*INFO :: ", "", filtered_pairs)
|
|
77
|
-
filtered_pairs = re.sub(" pairs discarded.*", "", filtered_pairs)
|
|
78
|
-
filtered_pairs = int(float(filtered_pairs))
|
|
79
|
-
else:
|
|
80
|
-
loops_pairs=0
|
|
81
|
-
uncuts_pairs=0
|
|
82
|
-
abnormal_pairs=0
|
|
83
|
-
filtered_pairs=0
|
|
84
|
-
pct_filtered = round(filtered_pairs/tot_pairs*100, 2)
|
|
85
|
-
pct_loops_pairs = round(loops_pairs/tot_pairs*100, 2)
|
|
86
|
-
pct_uncuts_pairs = round(uncuts_pairs/tot_pairs*100, 2)
|
|
87
|
-
pct_abnormal_pairs = round(abnormal_pairs/tot_pairs*100, 2)
|
|
88
|
-
|
|
89
|
-
# 5. Number (% of total) of PCR dups pairs
|
|
90
|
-
PCR_pairs = [s for s in log_lines if re.search("PCR duplicates have been filtered", s)]
|
|
91
|
-
if (len(PCR_pairs) > 0):
|
|
92
|
-
PCR_pairs = PCR_pairs[0]
|
|
93
|
-
PCR_pairs = re.sub(".*have been filtered out \(", "", PCR_pairs)
|
|
94
|
-
PCR_pairs = re.sub(" / .*", "", PCR_pairs)
|
|
95
|
-
PCR_pairs = int(float(PCR_pairs))
|
|
96
|
-
else:
|
|
97
|
-
PCR_pairs = 0
|
|
98
|
-
pct_PCR = round(PCR_pairs/tot_pairs*100, 2)
|
|
99
|
-
|
|
100
|
-
# 6. Number (%) of final pairs
|
|
101
|
-
kept_pairs=tot_pairs-filtered_pairs-PCR_pairs
|
|
102
|
-
pct_kept = round(kept_pairs/tot_pairs*100, 2)
|
|
103
|
-
|
|
104
|
-
# Open the log file and read its contents
|
|
105
|
-
stats_file_path = join(out_dir, prefix + ".stats.txt")
|
|
106
|
-
with open(stats_file_path, 'w') as stats_file:
|
|
107
|
-
stats_file.write("Sample: {prefix}\n".format(prefix = prefix))
|
|
108
|
-
stats_file.write("Total read pairs: {reads}\n".format(reads = "{:,}".format(fastq_pairs)))
|
|
109
|
-
stats_file.write("Mapped reads: {tot_mapped} ({pct_mapped}% of all reads)\n".format(
|
|
110
|
-
tot_mapped = "{:,}".format(tot_mapped),
|
|
111
|
-
pct_mapped = pct_mapped
|
|
112
|
-
)
|
|
113
|
-
)
|
|
114
|
-
stats_file.write("Unmapped reads: {tot_unmapped} ({pct_unmapped}% of all reads)\n".format(
|
|
115
|
-
tot_unmapped = "{:,}".format(tot_unmapped), pct_unmapped = pct_unmapped
|
|
116
|
-
))
|
|
117
|
-
stats_file.write("Recovered contacts: {tot_pairs} ({pct_pairs}% of all read pairs)\n".format(
|
|
118
|
-
tot_pairs = "{:,}".format(tot_pairs), pct_pairs = pct_pairs
|
|
119
|
-
))
|
|
120
|
-
stats_file.write("Final contacts: {kept_pairs} ({pct_kept}% of all contacts)\n".format(
|
|
121
|
-
kept_pairs = "{:,}".format(kept_pairs), pct_kept = pct_kept
|
|
122
|
-
))
|
|
123
|
-
stats_file.write(" Filtered out: {filtered_pairs} ({pct_filtered}% of all contacts)\n".format(
|
|
124
|
-
filtered_pairs = "{:,}".format(filtered_pairs), pct_filtered = pct_filtered
|
|
125
|
-
))
|
|
126
|
-
stats_file.write(" Loops: {loops_pairs} ({pct_loops_pairs}% of all contacts)\n".format(
|
|
127
|
-
loops_pairs = "{:,}".format(loops_pairs), pct_loops_pairs = pct_loops_pairs
|
|
128
|
-
))
|
|
129
|
-
stats_file.write(" Uncuts: {uncuts_pairs} ({pct_uncuts_pairs}% of all contacts)\n".format(
|
|
130
|
-
uncuts_pairs = "{:,}".format(uncuts_pairs), pct_uncuts_pairs = pct_uncuts_pairs
|
|
131
|
-
))
|
|
132
|
-
stats_file.write(" Weirds: {abnormal_pairs} ({pct_abnormal_pairs}% of all contacts)\n".format(
|
|
133
|
-
abnormal_pairs = "{:,}".format(abnormal_pairs), pct_abnormal_pairs = pct_abnormal_pairs
|
|
134
|
-
))
|
|
135
|
-
stats_file.write(" PCR duplicates: {PCR_pairs} ({pct_PCR}% of all contacts)\n".format(
|
|
136
|
-
PCR_pairs = "{:,}".format(PCR_pairs), pct_PCR = pct_PCR
|
|
137
|
-
))
|
|
138
|
-
|
|
139
|
-
stats = {
|
|
140
|
-
'Total read pairs': fastq_pairs,
|
|
141
|
-
'Mapped reads': tot_mapped,
|
|
142
|
-
'Unmapped reads': tot_unmapped,
|
|
143
|
-
'Recovered contacts': tot_pairs,
|
|
144
|
-
'Final contacts': kept_pairs,
|
|
145
|
-
'Filtered out': filtered_pairs,
|
|
146
|
-
'Loops': loops_pairs,
|
|
147
|
-
'Uncuts': uncuts_pairs,
|
|
148
|
-
'Weirds': abnormal_pairs,
|
|
149
|
-
'PCR duplicates': PCR_pairs
|
|
150
|
-
}
|
|
151
|
-
stats_json_path = join(out_dir, prefix + ".stats.json")
|
|
152
|
-
with open(stats_json_path, 'w') as json_file:
|
|
153
|
-
json.dump(stats, json_file, indent=4)
|
|
154
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '3.2.2'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|