-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.py
executable file
·47 lines (38 loc) · 1.82 KB
/
report.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
#! /usr/bin/env python
import csv, argparse, glob, re, os
parser = argparse.ArgumentParser()
parser.add_argument("BED")
args = parser.parse_args()
preport = {}
xreport = {}
rreport = {}
inputBED = glob.glob(args.BED)
#print inputBED
for sample in inputBED:
with open(sample) as f:
reader = csv.reader(f,delimiter='\t')
reader.next()
for row in reader:
organism = row[0]
xcov = row[4]
pcov = row[5]
#relab = row[6]
if organism not in preport and organism not in xreport:# and organism not in rreport:
preport[organism] = dict((os.path.split(k)[-1],0) for k in inputBED)
xreport[organism] = dict((os.path.split(k)[-1],0) for k in inputBED)
rreport[organism] = dict((os.path.split(k)[-1],0) for k in inputBED)
preport[organism][os.path.split(sample)[-1]] = pcov
xreport[organism][os.path.split(sample)[-1]] = xcov
#rreport[organism][os.path.split(sample)[-1]] = relab
with open("%s/breadth_merged.txt" % (os.path.split(inputBED[0])[0]), "w") as outfile:
outfile.write("organism\t%s\n" % "\t".join(preport.values()[0].keys()))
for organism in sorted(preport):
outfile.write("%s\t%s\n" %(organism, '\t'.join([str(preport[organism][x]) for x in preport[organism]])))
with open("%s/depth_merged.txt" % (os.path.split(inputBED[0])[0]), "w") as outfile:
outfile.write("organism\t%s\n" % "\t".join(xreport.values()[0].keys()))
for organism in sorted(xreport):
outfile.write("%s\t%s\n" %(organism, '\t'.join([str(xreport[organism][x]) for x in xreport[organism]])))
# with open("%s/abundances_merged.txt" % (os.path.split(inputBED[0])[0]), "w") as outfile:
# outfile.write("organism\t%s\n" % "\t".join(rreport.values()[0].keys()))
# for organism in rreport:
# outfile.write("%s\t%s\n" %(organism, '\t'.join([str(rreport[organism][x]) for x in rreport[organism]])))