forked from cjrubinlab/python_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalcCovGATKDepthFiles_1kb.py
47 lines (41 loc) · 1.15 KB
/
CalcCovGATKDepthFiles_1kb.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
import sys
import fileinput
import numpy
# This script takes as input Depth of coverage files generated by GATK DepthOfCoverage and calculates the sum of depths over 1kb windows
# for each ReadGroup ID (depth column). The maximum number of individuals (more specifically RG iDs) 170)
# Carl-Johan Rubin, Uppsala University, 2016
def CalcCov(infile):
counter=-1
Cov=0
counter2=0
array1=numpy.zeros([170],int)
cov1=0
pos=0
lastpos=0
for line in fileinput.input(infile):
counter2=counter2+1
counter=counter+1
line=line.replace('\n','')
line=line.replace(':','\t')
cols=line.split('\t')
lenCols=len(cols)
pos=0
if counter==1:
lastpos=pos
if counter >1:
pos=int(cols[1])
for iter in range(lenCols-4):
array1[iter]=int(cols[4+iter])+array1[iter]
if counter==999:
print str(cols[0]) + '\t' + str(lastpos)+ '\t' + str(pos)+ '\t',
for iter2 in range(lenCols-4):
cov1=array1[iter2]
print str(cov1) + '\t',
print '\n',
counter=0
array1=numpy.zeros([170],int)
if __name__ == '__main__':
if len(sys.argv) != 2:
print 'Wrong number of arguments!\n'
sys.exit(2)
CalcCov(sys.argv[1],)