Skip to content

Commit d25f405

Browse files
Dom LaetschDom Laetsch
authored andcommitted
new things
- fixes - sumcov
1 parent 6212622 commit d25f405

File tree

5 files changed

+77
-7
lines changed

5 files changed

+77
-7
lines changed

blobtools

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ commands:
1111
1212
comparecov compare BlobDB cov(s) to additional cov file
1313
bam2cov generate cov file from bam file
14+
sumcov sum coverage from multiple COV files
1415
1516
-h --help show this
1617
@@ -40,5 +41,7 @@ if __name__ == '__main__':
4041
exit(call(['python', main_dir + 'bam2cov.py'] + argv))
4142
elif args['<command>'] == 'comparecov':
4243
exit(call(['python', main_dir + 'comparecov.py'] + argv))
44+
elif args['<command>'] == 'sumcov':
45+
exit(call(['python', main_dir + 'sumcov.py'] + argv))
4346
else:
4447
exit("%r is not a blobtools command. See 'blobtools -h'." % args['<command>'])

comparecov.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
if (plotObj.title):
180180
plotObj.title = "%s.%s.%s" % (title, taxrule, cov_lib)
181181

182-
out_f = "%s.%s.%s.p%s.%s" % (title, hist_type, rank, max_group_plot, cov_lib)
182+
out_f = "%s.%s.%s.p%s.%s.%s" % (title, hist_type, rank, max_group_plot, scale, cov_lib)
183183
if out_prefix:
184184
out_f = "%s.%s" % (out_prefix, out_f)
185185
#if catcolour_dict:

lib/BtLog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def error(message, *argv):
2222
def progress(iteration, steps, max_value):
2323
if int(iteration == max_value):
2424
sys.stdout.write('\r')
25-
print "[PROGRESS]\t: %d%%" % (100)
25+
print "[PROGRESS]\t: %d%%" % (100),
2626
else:
2727
if int(iteration) % int(steps) == 0:
2828
sys.stdout.write('\r')

lib/BtPlot.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,17 @@ def set_format_scatterplot(axScatter, max_cov):
132132
axScatter.xaxis.labelpad = 20
133133
return axScatter
134134

135-
def set_format_covplot(axScatter, x_max, y_max, x_label, y_label):
136-
axScatter.set_xlabel(x_label, fontsize=35)
135+
def set_format_covplot(axScatter, x_max, y_max, x_label, y_label, scale, cov_lib):
136+
axScatter.set_xlabel(x_label + " " + cov_lib, fontsize=35)
137137
axScatter.set_ylabel(y_label, fontsize=35)
138138
axScatter.grid(True, which="major", lw=2., color=WHITE, linestyle='-')
139139
axScatter.set_axisbelow(True)
140-
axScatter.set_xlim( (0.01, x_max+100) )
141-
axScatter.set_ylim( (0.01, y_max+100) ) # This sets the max-Coverage so that all libraries + sum are at the same scale
140+
if scale == 'log':
141+
axScatter.set_xlim( (0.01, x_max+100) )
142+
axScatter.set_ylim( (0.01, y_max+100) )
143+
else:
144+
axScatter.set_xlim( (-10, x_max + (x_max*0.1) ) )
145+
axScatter.set_ylim( (-10, y_max + (y_max*0.1) ) )
142146
axScatter.xaxis.labelpad = 20
143147
axScatter.xaxis.labelpad = 20
144148
return axScatter
@@ -363,7 +367,7 @@ def plotScatterCov(self, cov_lib, cov_dict, info_flag, x_label, y_label, scale,
363367
# Setting up plots and axes
364368
plt.figure(1, figsize=(35,35), dpi=400)
365369
axScatter = plt.axes(rect_scatter, axisbg=BGGREY, yscale = scale, xscale = scale)
366-
axScatter = set_format_covplot(axScatter, x_max, y_max, x_label, y_label)
370+
axScatter = set_format_covplot(axScatter, x_max, y_max, x_label, y_label, scale, cov_lib)
367371
axHistx = plt.axes(rect_histx, axisbg=BGGREY)
368372
axHistx = set_format_hist_x_cov(axHistx, axScatter, scale)
369373
axHisty = plt.axes(rect_histy, axisbg=BGGREY)

sumcov.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""usage: blobtools sumcov -i FASTA -c COV...
5+
[-h|--help]
6+
7+
Options:
8+
-h --help show this
9+
10+
-i, --infile FASTA FASTA file of assembly. Headers are split at whitespaces.
11+
-c, --cov COV COV file(s) to sum up
12+
"""
13+
14+
from __future__ import division
15+
from docopt import docopt
16+
import lib.BtCore as bt
17+
import lib.BtLog as BtLog
18+
import lib.BtIO as BtIO
19+
import lib.BtPlot as BtPlot
20+
from os.path import dirname, isfile
21+
22+
def readFasta(infile):
23+
header = ''
24+
with open(infile) as fh:
25+
for l in fh:
26+
if l[0] == '>':
27+
yield l[1:-1].split()[0]
28+
else:
29+
pass
30+
31+
def parseFasta(infile):
32+
fasta_order = []
33+
fasta_dict = {}
34+
for name in readFasta(infile):
35+
fasta_order.append(name)
36+
fasta_dict[name] = 0.0
37+
return fasta_dict, fasta_order
38+
39+
if __name__ == '__main__':
40+
main_dir = dirname(__file__)
41+
#print data_dir
42+
args = docopt(__doc__)
43+
assembly_f = args['--infile']
44+
cov_fs = args['--cov']
45+
46+
fasta_dict = {}
47+
fasta_order = []
48+
if not isfile(assembly_f):
49+
BtLog.error('0', assembly_f)
50+
else:
51+
fasta_dict, fasta_order = parseFasta(assembly_f)
52+
53+
for cov_f in cov_fs:
54+
if not isfile(cov_f):
55+
BtLog.error('0', cov_f)
56+
else:
57+
lib_cov_dict = BtPlot.parseCovFile(cov_f)
58+
for name in fasta_order:
59+
fasta_dict[name] = fasta_dict.get(name, 0.0) + lib_cov_dict[name]
60+
61+
62+
for name in fasta_order:
63+
print "%s\t%s" % (name, fasta_dict[name])

0 commit comments

Comments
 (0)