-
Notifications
You must be signed in to change notification settings - Fork 50
/
ragtag_stats.py
92 lines (73 loc) · 3 KB
/
ragtag_stats.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
#!/usr/bin/env python
"""
MIT License
Copyright (c) 2021 Michael Alonge <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import sys
import argparse
from ragtag_utilities.AGPFile import AGPFile
def main():
parser = argparse.ArgumentParser(description="Calculate scaffolding statistics")
parser.add_argument("agp", nargs='?', default="", metavar="<ragtag.scaffolds.agp>", type=str, help="RagTag scaffolding AGP file")
parser.add_argument("confidence", nargs='?', default="", metavar="<ragtag.confidence.txt>", type=str, help="RagTag scaffolding confidence scores file")
args = parser.parse_args()
if not args.agp or not args.confidence:
parser.print_help()
sys.exit()
agp_file = args.agp
confidence_file = args.confidence
placed_bp = 0
placed_seq = 0
unplaced_bp = 0
unplaced_seq = 0
gap_bp = 0
gap_seq = 0
allowed_seq_types = {"A", "D", "F", "G", "O", "P", "W"}
allowed_gap_types = {"N", "U"}
# Get the set of placed sequences from the confidence scores file
placed_seqs = set()
with open(confidence_file, "r") as f:
f.readline() # discard header
for line in f:
header, g_score, l_score, o_score = line.rstrip().split("\t")
placed_seqs.add(header)
# Iterate through the AGP file
agp = AGPFile(agp_file, mode="r")
for line in agp.iterate_lines():
if line.is_gap:
gap_bp += line.gap_len
gap_seq += 1
else:
seq_len = line.comp_end - (line.comp_beg - 1)
if line.comp in placed_seqs:
placed_bp += seq_len
placed_seq += 1
else:
unplaced_bp += seq_len
unplaced_seq += 1
print("placed_sequences\tplaced_bp\tunplaced_sequences\tunplaced_bp\tgap_bp\tgap_sequences")
print("\t".join([
str(placed_seq),
str(placed_bp),
str(unplaced_seq),
str(unplaced_bp),
str(gap_bp),
str(gap_seq)
]))
if __name__ == "__main__":
main()