forked from Kevinnota/NED-flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocessing_summary.py
More file actions
executable file
·79 lines (66 loc) · 2.39 KB
/
Copy pathpreprocessing_summary.py
File metadata and controls
executable file
·79 lines (66 loc) · 2.39 KB
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
#!/usr/bin/env python
import argparse
import re
import json
parser = argparse.ArgumentParser(prog='Taxon classifier', description='', usage='%(prog)s [options]')
parser.add_argument('--fastp_json', "-fj", nargs='+', help='input fastp json files')
parser.add_argument('--dust_summary', "-ds", nargs='+', help='output from dustmasker filter')
parser.add_argument('--version', help='print version',action='store_true', default=False)
args=parser.parse_args()
#version="taxon classifier - v1.0 18 jun 2025"
### New tool to calculate library filtering stats from fastp output
version="taxon classifier - v1.0 18 jun 2025"
def read_dust_filter_file():
lib2dust_removed_dict={}
for dust_summary in args.dust_summary:
file = open(dust_summary, 'r')
try:
for row in file:
if "library =" in row:
library = re.sub('library = ', '', row.strip())
if 'number sequence removed' in row:
n_seq_removed = re.sub('number sequence removed|, all.*', '', row.strip())
#print(f"{library}, {n_seq_removed}")
lib2dust_removed_dict[library] = n_seq_removed
pass
except:
pass
return lib2dust_removed_dict
print(lib2dust_removed_dict)
def read_fastp_json_fils():
header = ['library',
'N_reads_before_filter',
'N_reads_after_filter',
'duplication_rate',
'low_quality_reads',
'too_many_N_reads',
'low_complexity_reads',
'too_short_reads',
'low_dust_score']
print('\t'.join(header))
for log in args.fastp_json:
#print(log)
#libary_name = re.sub('.*/|s_._|_S.*', '', re.sub('_report.json', '', log))
libary_name = re.sub('.*/|s_._', '', re.sub('_report.json', '', log))
try:
dust_removed=lib2dust_removed_dict[libary_name]
except:
dust_removed="NA"
pass
log_file = json.load(open(log, 'r'))
value_list=[libary_name,
log_file['summary']['before_filtering']['total_reads'],
log_file['summary']['after_filtering']['total_reads'],
log_file['duplication']['rate'],
log_file['filtering_result']['low_quality_reads'],
log_file['filtering_result']['too_many_N_reads'],
log_file['filtering_result']['low_complexity_reads'],
log_file['filtering_result']['too_short_reads'],
dust_removed]
print("\t".join(str(v) for v in value_list))
if __name__ == '__main__':
if args.version == True :
print(version)
quit()
lib2dust_removed_dict = read_dust_filter_file()
read_fastp_json_fils()