File: coverage_hist.py

package info (click to toggle)
spades 3.13.1+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 22,172 kB
  • sloc: cpp: 136,213; ansic: 48,218; python: 16,809; perl: 4,252; sh: 2,115; java: 890; makefile: 507; pascal: 348; xml: 303
file content (55 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python3 -O

############################################################################
# Copyright (c) 2015 Saint Petersburg State University
# Copyright (c) 2011-2014 Saint Petersburg Academic University
# All Rights Reserved
# See file LICENSE for details.
############################################################################


#Calculate coverage from raw file

import sys


def main():

    if len(sys.argv) < 4:
	    print("Usage: <coverage file> <output> <bin size> ");
	    exit(0)

    inFile = open(sys.argv[1])
    outFile = open(sys.argv[2], 'w')

    bin = int(sys.argv[3])
    
    hist = []
    for line in inFile:
            hist.append(int(line.split()[1]))
	    
    maxLen = len(hist)
    print(maxLen)
    newHist = [0 for i in range((maxLen + 1) / bin + 2)]
    zeroList = []

    for i in range(maxLen):
            hpos = int(i/bin)
	    newHist[hpos] += hist[i]

            if hist[i] == 0:
                    zeroList.append(hpos)

    zeroSet = set(zeroList)

    for i in range((maxLen + 1) / bin + 1):
	    outFile.write(str(i) + ' ' + str(newHist[i] / bin) + '\n')
            if i in zeroSet:
                    outFile.write(str(i) + ' 0\n')

    inFile.close()
    outFile.close()


if __name__ == '__main__':
    main()