-
Notifications
You must be signed in to change notification settings - Fork 0
/
readcountcorrectBG.py
39 lines (32 loc) · 1.09 KB
/
readcountcorrectBG.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
from __future__ import division
import sys
import os
def calmp(num_of_reads, total_reads):
mp = float(num_of_reads)/(int(total_reads)/1000000)
return mp
def gettotalreadsfromflagstat(flagstatfile):
f = open(flagstatfile)
lines = f.readlines()
total_reads = lines[0]
total_reads = int(total_reads.split(" ")[0])
mapped_reads = lines[4]
mapped_reads = int(mapped_reads.split(" ")[0])
print "total reads", total_reads
print "mapped_reads", mapped_reads
return mapped_reads
def main(Bedgraphfile, flagstatfile, readcountcorrBedgraphfile):
total_reads = gettotalreadsfromflagstat(flagstatfile)
wf = open(readcountcorrBedgraphfile, "w")
f = open(Bedgraphfile)
for line in f:
line = line.strip("\n")
line = line.split("\t")
num_of_reads = line[-1]
mp = calmp(num_of_reads, total_reads)
line[-1] = mp
wf.write("\t".join(map(str,line))+"\n")
wf.close()
f.close()
if __name__=="__main__":
Bedgraphfile, flagstatfile, readcountcorrBedgraphfile = sys.argv[1],sys.argv[2], sys.argv[3]
main(Bedgraphfile, flagstatfile, readcountcorrBedgraphfile)