hicstuff 3.2.1__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.1/hicstuff.egg-info → hicstuff-3.2.3}/PKG-INFO +1 -1
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/commands.py +18 -3
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/io.py +6 -18
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/main.py +1 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/pipeline.py +52 -1
- hicstuff-3.2.3/hicstuff/stats.py +185 -0
- hicstuff-3.2.3/hicstuff/version.py +1 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3/hicstuff.egg-info}/PKG-INFO +1 -1
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff.egg-info/SOURCES.txt +1 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/setup.py +1 -1
- hicstuff-3.2.1/hicstuff/version.py +0 -1
- {hicstuff-3.2.1 → hicstuff-3.2.3}/LICENSE +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/MANIFEST.in +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/README.md +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/__init__.py +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/cutsite.py +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/digest.py +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/distance_law.py +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/filter.py +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/hicstuff.py +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/iteralign.py +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/log.py +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff/view.py +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff.egg-info/dependency_links.txt +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff.egg-info/entry_points.txt +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff.egg-info/requires.txt +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/hicstuff.egg-info/top_level.txt +0 -0
- {hicstuff-3.2.1 → hicstuff-3.2.3}/requirements.txt +0 -0
- {hicstuff-3.2.1 → 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
|
|
@@ -1435,7 +1435,7 @@ def check_is_fasta(in_file):
|
|
|
1435
1435
|
|
|
1436
1436
|
def check_fastq_entries(in_file):
|
|
1437
1437
|
"""
|
|
1438
|
-
Check how many reads are in the input fastq.
|
|
1438
|
+
Check how many reads are in the input fastq.
|
|
1439
1439
|
|
|
1440
1440
|
Parameters
|
|
1441
1441
|
----------
|
|
@@ -1450,24 +1450,12 @@ def check_fastq_entries(in_file):
|
|
|
1450
1450
|
|
|
1451
1451
|
with open(in_file, 'rb') as f:
|
|
1452
1452
|
is_gzip = f.read(2) == b'\x1f\x8b'
|
|
1453
|
-
|
|
1454
1453
|
if is_gzip:
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
stdout=sp.PIPE,
|
|
1458
|
-
stderr=sp.PIPE,
|
|
1459
|
-
shell = True,
|
|
1460
|
-
encoding = 'utf-8'
|
|
1461
|
-
).stdout.removesuffix("\n").split(" ")[0]
|
|
1454
|
+
with gzip.open(in_file, "rt") as input_fastq:
|
|
1455
|
+
n_lines = sum(1 for line in input_fastq)
|
|
1462
1456
|
else:
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
stdout=sp.PIPE,
|
|
1466
|
-
stderr=sp.PIPE,
|
|
1467
|
-
shell = True,
|
|
1468
|
-
encoding = 'utf-8'
|
|
1469
|
-
).stdout.removesuffix("\n").split(" ")[0]
|
|
1470
|
-
|
|
1457
|
+
with open(in_file, "r") as input_fastq:
|
|
1458
|
+
n_lines = sum(1 for line in input_fastq)
|
|
1471
1459
|
n_reads = int(n_lines)/4
|
|
1472
1460
|
return n_reads
|
|
1473
1461
|
|
|
@@ -1491,6 +1479,6 @@ def check_bam_entries(in_file):
|
|
|
1491
1479
|
stdout=sp.PIPE,
|
|
1492
1480
|
stderr=sp.PIPE,
|
|
1493
1481
|
encoding = 'utf-8'
|
|
1494
|
-
).stdout
|
|
1482
|
+
).stdout[:-2]
|
|
1495
1483
|
|
|
1496
1484
|
return int(n_reads)
|
|
@@ -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.
|
|
@@ -23,8 +23,11 @@ import hicstuff.filter as hcf
|
|
|
23
23
|
import hicstuff.io as hio
|
|
24
24
|
import hicstuff.distance_law as hcdl
|
|
25
25
|
import hicstuff.cutsite as hcc
|
|
26
|
+
import hicstuff.stats as hcs
|
|
26
27
|
import matplotlib
|
|
27
28
|
import pathlib
|
|
29
|
+
import pairtools
|
|
30
|
+
from packaging.version import Version
|
|
28
31
|
from hicstuff.version import __version__
|
|
29
32
|
import hicstuff.log as hcl
|
|
30
33
|
from hicstuff.log import logger
|
|
@@ -312,6 +315,9 @@ def filter_pcr_dup(pairs_idx_file, filtered_file):
|
|
|
312
315
|
"%d%% PCR duplicates have been filtered out (%d / %d pairs) "
|
|
313
316
|
% (100 * round(filter_count / reads_count, 3), filter_count, reads_count)
|
|
314
317
|
)
|
|
318
|
+
logger.info(
|
|
319
|
+
"%d pairs remaining after removing PCR duplicates", reads_count - filter_count
|
|
320
|
+
)
|
|
315
321
|
|
|
316
322
|
|
|
317
323
|
def pairs2cool(pairs_file, cool_file, bins_file, exclude):
|
|
@@ -883,6 +889,7 @@ def full_pipeline(
|
|
|
883
889
|
pairs_idx = input1
|
|
884
890
|
|
|
885
891
|
# Perform genome alignment
|
|
892
|
+
nreads_input1 = 0
|
|
886
893
|
if start_stage == 0:
|
|
887
894
|
|
|
888
895
|
# Check number of reads in both fastqs
|
|
@@ -892,7 +899,7 @@ def full_pipeline(
|
|
|
892
899
|
if (nreads_input1 != nreads_input2):
|
|
893
900
|
logger.error("Fastq files do not have the same number of reads.")
|
|
894
901
|
else:
|
|
895
|
-
logger.info("{n} reads found in each fastq file.".format(n = nreads_input1))
|
|
902
|
+
logger.info("{n} reads found in each fastq file.".format(n = int(nreads_input1)))
|
|
896
903
|
|
|
897
904
|
# Define mapping choice (default normal):
|
|
898
905
|
if mapping == "normal":
|
|
@@ -1006,6 +1013,26 @@ def full_pipeline(
|
|
|
1006
1013
|
)
|
|
1007
1014
|
os.rename(pairs_idx + ".sorted", pairs_idx)
|
|
1008
1015
|
|
|
1016
|
+
# Count total pairs
|
|
1017
|
+
tot_pairs = 0
|
|
1018
|
+
with open(pairs_idx, "r") as file:
|
|
1019
|
+
for line in file:
|
|
1020
|
+
if line.startswith('#'):
|
|
1021
|
+
continue
|
|
1022
|
+
else:
|
|
1023
|
+
tot_pairs += 1
|
|
1024
|
+
if nreads_input1 != 0:
|
|
1025
|
+
logger.info(
|
|
1026
|
+
"{0} pairs successfully mapped ({1}%)".format(
|
|
1027
|
+
tot_pairs, round(100 * tot_pairs / (nreads_input1), 2)
|
|
1028
|
+
)
|
|
1029
|
+
)
|
|
1030
|
+
else:
|
|
1031
|
+
logger.info(
|
|
1032
|
+
"{0} pairs successfully mapped".format(tot_pairs)
|
|
1033
|
+
)
|
|
1034
|
+
|
|
1035
|
+
# Filter pairs if requested
|
|
1009
1036
|
if filter_events:
|
|
1010
1037
|
uncut_thr, loop_thr = hcf.get_thresholds(
|
|
1011
1038
|
pairs_idx, plot_events=plot, fig_path=dist_plot, prefix=prefix
|
|
@@ -1067,6 +1094,19 @@ def full_pipeline(
|
|
|
1067
1094
|
# Build matrix from pairs.
|
|
1068
1095
|
if mat_fmt == "cool":
|
|
1069
1096
|
|
|
1097
|
+
# Log which pairs file is being used and how many pairs are listed
|
|
1098
|
+
pairs_count = 0
|
|
1099
|
+
with open(use_pairs, "r") as file:
|
|
1100
|
+
for line in file:
|
|
1101
|
+
if line.startswith('#'):
|
|
1102
|
+
continue
|
|
1103
|
+
else:
|
|
1104
|
+
pairs_count += 1
|
|
1105
|
+
logger.info(
|
|
1106
|
+
"Generating matrix from pairs file %s (%d pairs in the file) ",
|
|
1107
|
+
use_pairs, pairs_count
|
|
1108
|
+
)
|
|
1109
|
+
|
|
1070
1110
|
# Name matrix file in .cool
|
|
1071
1111
|
mat = os.path.splitext(mat)[0] + ".cool"
|
|
1072
1112
|
|
|
@@ -1099,6 +1139,15 @@ def full_pipeline(
|
|
|
1099
1139
|
tmp_dir=tmp_dir,
|
|
1100
1140
|
)
|
|
1101
1141
|
|
|
1142
|
+
# Get stats on the pipeline
|
|
1143
|
+
try:
|
|
1144
|
+
logger.info("Fetching mapping and pairing stats")
|
|
1145
|
+
stats = hcs.get_pipeline_stats(log_file)
|
|
1146
|
+
logger.info(stats)
|
|
1147
|
+
except IndexError:
|
|
1148
|
+
logger.warning("IndexError. Stats not compiled.")
|
|
1149
|
+
pass
|
|
1150
|
+
|
|
1102
1151
|
# Move final pairs file to main dir.
|
|
1103
1152
|
p = pathlib.Path(use_pairs).absolute()
|
|
1104
1153
|
pairsf = p.parents[1] / p.name
|
|
@@ -1110,6 +1159,8 @@ def full_pipeline(
|
|
|
1110
1159
|
sort_args = "--output {out} --tmpdir {tmp_dir}".format(
|
|
1111
1160
|
out = sorted_pairsf, tmp_dir = tmp_dir
|
|
1112
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"
|
|
1113
1164
|
sp.call(pairstools_cmd + sort_args.split(" ") + [pairsf], shell=False)
|
|
1114
1165
|
os.remove(pairsf)
|
|
1115
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'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '3.2.1'
|
|
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
|