Skip to content

Commit 7eceb42

Browse files
Dom LaetschDom Laetsch
Dom Laetsch
authored and
Dom Laetsch
committed
v0.9.13
- fixed bug in covplot - renamed main scripts
1 parent b2b338c commit 7eceb42

File tree

4 files changed

+63
-62
lines changed

4 files changed

+63
-62
lines changed

plot.py renamed to blobplot.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
"""usage: blobtools plot -i BLOBDB [-p INT] [-l INT] [-c] [-n] [-s]
5-
[-r RANK] [-x TAXRULE] [--label GROUPS...]
6-
[-o PREFIX] [-m] [--sort ORDER] [--hist HIST] [--title]
7-
[--colours FILE] [--include FILE] [--exclude FILE]
8-
[--format FORMAT] [--noblobs] [--noreads]
9-
[--refcov FILE] [--catcolour FILE]
10-
[-h|--help]
4+
"""usage: blobtools blobplot -i BLOBDB [-p INT] [-l INT] [-c] [-n] [-s]
5+
[-r RANK] [-x TAXRULE] [--label GROUPS...]
6+
[-o PREFIX] [-m] [--sort ORDER] [--hist HIST] [--title]
7+
[--colours FILE] [--include FILE] [--exclude FILE]
8+
[--format FORMAT] [--noblobs] [--noreads]
9+
[--refcov FILE] [--catcolour FILE]
10+
[-h|--help]
1111
1212
Options:
1313
-h --help show this
1414
-i, --infile BLOBDB BlobDB file (created with "blobtools create")
15-
-p, --plotgroups INT Number of (taxonomic) groups to plot, remaining
15+
-p, --plotgroups INT Number of (taxonomic) groups to plot, remaining
1616
groups are placed in 'other' [default: 7]
1717
-l, --length INT Minimum sequence length considered for plotting [default: 100]
1818
-c, --cindex Colour blobs by 'c index' [default: False]
1919
-n, --nohit Hide sequences without taxonomic annotation [default: False]
2020
-s, --noscale Do not scale sequences by length [default: False]
2121
-o, --out PREFIX Output prefix
22-
-m, --multiplot Multi-plot. Print plot after addition of each (taxonomic) group
22+
-m, --multiplot Multi-plot. Print plot after addition of each (taxonomic) group
2323
[default: False]
2424
--sort <ORDER> Sort order for plotting [default: span]
2525
span : plot with decreasing span
26-
count : plot with decreasing count
27-
--hist <HIST> Data for histograms [default: span]
26+
count : plot with decreasing count
27+
--hist <HIST> Data for histograms [default: span]
2828
span : span-weighted histograms
2929
count : count histograms
3030
--title Add title of BlobDB to plot [default: False]
3131
-r, --rank RANK Taxonomic rank used for colouring of blobs [default: phylum]
32-
(Supported: species, genus, family, order, phylum, superkingdom)
33-
-x, --taxrule TAXRULE Taxrule which has been used for computing taxonomy
32+
(Supported: species, genus, family, order, phylum, superkingdom)
33+
-x, --taxrule TAXRULE Taxrule which has been used for computing taxonomy
3434
(Supported: bestsum, bestsumorder) [default: bestsum]
35-
--label GROUPS... Relabel (taxonomic) groups (not 'all' or 'other'),
35+
--label GROUPS... Relabel (taxonomic) groups (not 'all' or 'other'),
3636
e.g. "Bacteria=Actinobacteria,Proteobacteria"
3737
--colours COLOURFILE File containing colours for (taxonomic) groups
3838
--exclude GROUPS.. Place these (taxonomic) groups in 'other',
3939
e.g. "Actinobacteria,Proteobacteria"
40-
--format FORMAT Figure format for plot (png, pdf, eps, jpeg,
40+
--format FORMAT Figure format for plot (png, pdf, eps, jpeg,
4141
ps, svg, svgz, tiff) [default: png]
4242
--noblobs Omit blobplot [default: False]
4343
--noreads Omit plot of reads mapping [default: False]
44-
--refcov FILE File containing number of "total" and "mapped" reads
44+
--refcov FILE File containing number of "total" and "mapped" reads
4545
per coverage file. (e.g.: bam0,900,100). If provided, info
46-
will be used in read coverage plot(s).
47-
--catcolour FILE Colour plot based on categories from FILE
48-
(format : "seq\tcategory").
49-
46+
will be used in read coverage plot(s).
47+
--catcolour FILE Colour plot based on categories from FILE
48+
(format : "seq\tcategory").
49+
5050
"""
5151

5252
from __future__ import division
@@ -64,7 +64,7 @@
6464
#print data_dir
6565
args = docopt(__doc__)
6666
blobdb_f = args['--infile']
67-
rank = args['--rank']
67+
rank = args['--rank']
6868
c_index = args['--cindex']
6969
min_length = int(args['--length'])
7070
multiplot = args['--multiplot']
@@ -79,7 +79,7 @@
7979
labels = args['--label']
8080
colour_f = args['--colours']
8181
exclude_groups = args['--exclude']
82-
format = args['--format']
82+
format = args['--format']
8383
no_plot_blobs = args['--noblobs']
8484
no_plot_reads = args['--noreads']
8585
refcov_f = args['--refcov']
@@ -96,23 +96,23 @@
9696
# Are sort_order and hist_type sane?
9797
if not sort_order in ['span', 'count']:
9898
BtLog.error('14', sort_order)
99-
if not hist_type in ['span', 'count']:
99+
if not hist_type in ['span', 'count']:
100100
BtLog.error('15', hist_type)
101101

102102
# is taxrule provided?
103103
if taxrule not in TAXRULES:
104104
BtLog.error('8', taxrule)
105105

106106
# compute labels if supplied
107-
107+
108108
user_labels = BtPlot.parse_labels(labels)
109-
109+
110110
if (exclude_groups):
111111
if "," in exclude_groups:
112112
exclude_groups = exclude_groups.rsplit(",")
113113
else:
114114
exclude_groups = exclude_groups
115-
115+
116116
refcov_dict = {}
117117
if (refcov_f):
118118
refcov_dict = BtPlot.parseRefCov(refcov_f)
@@ -122,7 +122,7 @@
122122
BtLog.error('24')
123123
elif (catcolour_f):
124124
catcolour_dict = BtPlot.parseCatColour(catcolour_f)
125-
else:
125+
else:
126126
pass
127127

128128
# Load BlobDb
@@ -137,7 +137,7 @@
137137
# Is taxrule sane and was it computed?
138138
if taxrule not in blobDB.taxrules:
139139
BtLog.error('11', taxrule, blobDB.taxrules)
140-
140+
141141
data_dict, max_cov, cov_lib_dict = blobDB.getPlotData(rank, min_length, hide_nohits, taxrule, c_index, catcolour_dict)
142142
plotObj = BtPlot.PlotObj(data_dict, cov_lib_dict)
143143
plotObj.exclude_groups = exclude_groups
@@ -150,7 +150,7 @@
150150
plotObj.max_group_plot = max_group_plot
151151
plotObj.group_order = BtPlot.getSortedGroups(data_dict, sort_order)
152152
plotObj.labels.update(plotObj.group_order)
153-
153+
154154
if (user_labels):
155155
for group, label in user_labels.items():
156156
plotObj.labels.add(label)

blobtools

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ usage: blobtools <command> [<args>...] [--help]
77
commands:
88
create create a BlobDB
99
view print BlobDB as a table
10-
plot plot BlobDB as a blobplot
10+
blobplot plot BlobDB as a blobplot
1111
12-
comparecov compare BlobDB cov(s) to additional cov file
12+
covplot compare BlobDB cov(s) to additional cov file
1313
bam2cov generate cov file from bam file
1414
sumcov sum coverage from multiple COV files
1515
@@ -26,7 +26,7 @@ from docopt import docopt
2626
if __name__ == '__main__':
2727
main_dir = join(dirname(__file__), '')
2828
args = docopt(__doc__,
29-
version='version 0.9.8',
29+
version='version 0.9.13',
3030
options_first=True)
3131
#print(args)
3232

@@ -35,13 +35,13 @@ if __name__ == '__main__':
3535
exit(call(['python', main_dir + 'create.py'] + argv))
3636
elif args['<command>'] == 'view':
3737
exit(call(['python', main_dir + 'view.py'] + argv))
38-
elif args['<command>'] == 'plot':
38+
elif args['<command>'] == 'blobplot' or args['<command>'] == 'plot':
3939
exit(call(['python', main_dir + 'plot.py'] + argv))
4040
elif args['<command>'] == 'bam2cov':
4141
exit(call(['python', main_dir + 'bam2cov.py'] + argv))
42-
elif args['<command>'] == 'comparecov':
43-
exit(call(['python', main_dir + 'comparecov.py'] + argv))
42+
elif args['<command>'] == 'covplot' or args['<command>'] == 'comparecov':
43+
exit(call(['python', main_dir + 'covplot.py'] + argv))
4444
elif args['<command>'] == 'sumcov':
45-
exit(call(['python', main_dir + 'sumcov.py'] + argv))
45+
exit(call(['python', main_dir + 'sumcov.py'] + argv))
4646
else:
47-
exit("%r is not a blobtools command. See 'blobtools -h'." % args['<command>'])
47+
exit("%r is not a blobtools command. See 'blobtools -h'." % args['<command>'])

comparecov.py renamed to covplot.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
"""usage: blobtools comparecov -i BLOBDB -c COV [-p INT] [-l INT] [-n] [-s]
4+
"""usage: blobtools covplot -i BLOBDB -c COV [-p INT] [-l INT] [-n] [-s]
55
[--xlabel XLABEL] [--ylabel YLABEL]
66
[--log] [--xmax FLOAT] [--ymax FLOAT]
77
[-r RANK] [-x TAXRULE] [-o PREFIX] [-m] [--title]
88
[--sort ORDER] [--hist HIST] [--format FORMAT]
9-
[-h|--help]
9+
[-h|--help]
1010
1111
Options:
1212
-h --help show this
1313
-i, --infile BLOBDB BlobDB file
1414
-c, --cov COV COV file used for y-axis
15-
15+
1616
--xlabel XLABEL Label for x-axis [default: BlobDB_cov]
1717
--ylabel YLABEL Label for y-axis [default: CovFile_cov]
1818
--log Plot log-scale axes
1919
--xmax FLOAT Maximum values for x-axis [default: 1e10]
2020
--ymax FLOAT Maximum values for y-axis [default: 1e10]
2121
22-
-p, --plotgroups INT Number of (taxonomic) groups to plot, remaining
22+
-p, --plotgroups INT Number of (taxonomic) groups to plot, remaining
2323
groups are placed in 'other' [default: 7]
2424
-r, --rank RANK Taxonomic rank used for colouring of blobs [default: phylum]
25-
-x, --taxrule TAXRULE Taxrule which has been used for computing taxonomy
25+
-x, --taxrule TAXRULE Taxrule which has been used for computing taxonomy
2626
(Supported: bestsum, bestsumorder) [default: bestsum]
2727
--sort <ORDER> Sort order for plotting [default: span]
2828
span : plot with decreasing span
29-
count : plot with decreasing count
30-
--hist <HIST> Data for histograms [default: span]
29+
count : plot with decreasing count
30+
--hist <HIST> Data for histograms [default: span]
3131
span : span-weighted histograms
3232
count : count histograms
3333
@@ -36,9 +36,9 @@
3636
-n, --nohit Hide sequences without taxonomic annotation [default: False]
3737
-s, --noscale Do not scale sequences by length [default: False]
3838
-o, --out PREFIX Output prefix
39-
-m, --multiplot Multi-plot. Print plot after addition of each (taxonomic) group
39+
-m, --multiplot Multi-plot. Print plot after addition of each (taxonomic) group
4040
[default: False]
41-
--format FORMAT Figure format for plot (png, pdf, eps, jpeg,
41+
--format FORMAT Figure format for plot (png, pdf, eps, jpeg,
4242
ps, svg, svgz, tiff) [default: png]
4343
"""
4444

@@ -58,12 +58,12 @@
5858
args = docopt(__doc__)
5959
blobdb_f = args['--infile']
6060
cov_f = args['--cov']
61-
x_label = args['--xlabel']
61+
x_label = args['--xlabel']
6262
y_label = args['--ylabel']
63-
scale = args['--log']
63+
scale = args['--log']
6464
x_max = float(args['--xmax'])
6565
y_max = float(args['--ymax'])
66-
rank = args['--rank']
66+
rank = args['--rank']
6767
min_length = int(args['--length'])
6868
multiplot = args['--multiplot']
6969
hide_nohits = args['--nohit']
@@ -77,7 +77,7 @@
7777
#labels = args['--label']
7878
#colour_f = args['--colours']
7979
#exclude_groups = args['--exclude']
80-
format = args['--format']
80+
format = args['--format']
8181
#no_plot_blobs = args['--noblobs']
8282
#no_plot_reads = args['--noreads']
8383
#refcov_f = args['--refcov']
@@ -90,25 +90,25 @@
9090
# Does cov_f exist ?
9191
if not isfile(cov_f):
9292
BtLog.error('0', cov_f)
93-
# parse cov file in dict
93+
# parse cov file in dict
9494
cov_dict = BtPlot.parseCovFile(cov_f)
95-
95+
9696
# Are ranks sane ?
9797
if rank not in RANKS:
9898
BtLog.error('9', rank)
9999

100100
# Are sort_order and hist_type sane?
101101
if not sort_order in ['span', 'count']:
102102
BtLog.error('14', sort_order)
103-
if not hist_type in ['span', 'count']:
103+
if not hist_type in ['span', 'count']:
104104
BtLog.error('15', hist_type)
105105

106106
# is taxrule provided?
107107
if taxrule not in TAXRULES:
108108
BtLog.error('8', taxrule)
109109

110110
# compute labels if supplied
111-
111+
112112
#user_labels = BtPlot.parse_labels(labels)
113113
#
114114
#if (exclude_groups):
@@ -126,7 +126,7 @@
126126
# BtLog.error('24')
127127
#elif (catcolour_f):
128128
# catcolour_dict = BtPlot.parseCatColour(catcolour_f)
129-
#else:
129+
#else:
130130
# pass
131131

132132
# Load BlobDb
@@ -146,15 +146,15 @@
146146
# Is taxrule sane and was it computed?
147147
if taxrule not in blobDB.taxrules:
148148
BtLog.error('11', taxrule, blobDB.taxrules)
149-
150-
data_dict, max_cov, cov_libs, cov_libs_total_reads = blobDB.getPlotData(rank, min_length, hide_nohits, taxrule, False, False)
151-
plotObj = BtPlot.PlotObj(data_dict, cov_libs, cov_libs_total_reads)
149+
150+
data_dict, max_cov, cov_lib_dict = blobDB.getPlotData(rank, min_length, hide_nohits, taxrule, False, False)
151+
plotObj = BtPlot.PlotObj(data_dict, cov_lib_dict)
152152
#plotObj.exclude_groups = exclude_groups
153153
if max_cov < x_max:
154154
x_max = max_cov
155155
if max_cov < y_max:
156156
y_max = max_cov
157-
157+
158158
if (scale):
159159
scale = 'log'
160160
else:
@@ -169,7 +169,7 @@
169169
plotObj.max_group_plot = max_group_plot
170170
plotObj.group_order = BtPlot.getSortedGroups(data_dict, sort_order)
171171
plotObj.labels.update(plotObj.group_order)
172-
172+
173173
#if (user_labels):
174174
# for group, label in user_labels.items():
175175
# plotObj.labels.add(label)
@@ -198,7 +198,7 @@
198198
# out_f = "%s.%s" % (out_f, "label_" + "_".join(set([name for name in user_labels.values()])))
199199
out_f = "%s.%s.%s" % (out_f, min_length, taxrule)
200200
plotObj.out_f = out_f
201-
201+
202202
plotObj.plotScatterCov(cov_lib, cov_dict, info_flag, x_label, y_label, scale, x_max, y_max)
203203
info_flag = 0
204204
plotObj.write_stats()

lib/BtIO.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def readBam(infile, set_of_blobs):
106106
read_cov_dict = {}
107107
cigar_match_re = re.compile(r"(\d+)M") # only gets digits before M's
108108
# execute samtools to get only mapped reads
109-
command = "samtools view -F 4 " + infile
109+
#command = "samtools view -F 12 -F 256" + infile
110+
command = "samtools view -F 4" + infile
110111
# ADD flag picard -F 1028 to not consider optical duplicates
111112
#command = "samtools view -F 1028 " + infile
112113
# only one counter since only yields mapped reads

0 commit comments

Comments
 (0)