Skip to content

Commit 4ba9e4e

Browse files
Dom LaetschDom Laetsch
authored andcommitted
...
1 parent 5f75776 commit 4ba9e4e

File tree

4 files changed

+28
-66
lines changed

4 files changed

+28
-66
lines changed

lib/BtCore.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def load(self, BlobDb_f):
115115
self.hitLibs = blobDict['hitLibs']
116116
self.taxrules = blobDict['taxrules']
117117

118-
def getArrays(self, rank, min_length, hide_nohits, taxrule, c_index, cluster_d):
118+
def getArrays(self, rank, min_length, hide_nohits, taxrule, c_index, label_d):
119119
from numpy import array
120120
summary_dict = {}
121121
data_list = []
@@ -129,8 +129,8 @@ def getArrays(self, rank, min_length, hide_nohits, taxrule, c_index, cluster_d):
129129
tax = str(blob['taxonomy'][taxrule][rank]['c_index'])
130130
else:
131131
tax = blob['taxonomy'][taxrule][rank]['tax']
132-
if cluster_d and tax in cluster_d:
133-
tax = cluster_d[tax]
132+
if label_d and tax in label_d:
133+
tax = label_d[tax]
134134
if not tax in summary_dict:
135135
summary_dict[tax] = {'count_total' : 0,
136136
'count_hidden' : 0,
@@ -204,8 +204,9 @@ def parseCovs(self, covLibObjs):
204204
covLib.cov_sum += cov
205205
self.dict_of_blobs[name].addCov(covLib.name, cov)
206206
elif covLib.fmt == 'cas':
207-
for name, cov in BtIO.readCas(covLib.f, set(self.dict_of_blobs)):
208-
pass
207+
for name, cov in BtIO.readCas(covLib.f, self.order_of_blobs):
208+
covLib.cov_sum += cov
209+
self.dict_of_blobs[name].addCov(covLib.name, cov)
209210
elif covLib.fmt == 'cov':
210211
for name, cov in BtIO.readCov(covLib.f, set(self.dict_of_blobs)):
211212
covLib.cov_sum += cov

lib/BtIO.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from os.path import basename, isfile, abspath
1717
import os
1818
import lib.BtLog as BtLog
19-
import lib.BtMisc as BtMisc
2019

2120
def parseList(infile):
2221
with open(infile) as fh:
@@ -139,16 +138,21 @@ def readCov(infile, set_of_blobs):
139138
BtLog.error('3', name, infile)
140139
yield name, cov
141140

142-
def readCas(infile, set_of_blobs):
141+
def readCas(infile, order_of_blobs):
142+
cas_line_re = re.compile(r"\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+.\d{2})\s+(\d+)\s+(\d+.\d{2})")
143143
output = ''
144144
if not (is_exe('clc_mapping_info')):
145145
BtLog.error('20')
146146
else:
147147
command = "clc_mapping_info -s -f " + infile
148148
if (runCmd(command)):
149149
for line in runCmd(command):
150-
output += line
151-
print output
150+
match = cas_line_re.search(line)
151+
if match:
152+
idx = int(match.group(1)) - 1 # -1 because index of contig list starts with zero
153+
name = order_of_blobs[idx]
154+
cov = float(match.group(4))
155+
yield name, cov
152156
#error_CAS, message = commands.getstatusoutput("clc_mapping_info -s -f " + infile)
153157
#if (error_CAS):
154158
# sys.exit("[ERROR] - Please add clc_mapping_info to you PATH variable.")

plot.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"""usage: blobtools plot --i <BLOBDB> [--p <MAXTAX>] [--l <LEN>] [--c] [--n] [--x]
55
[--o <PREFIX>] [--m] [--sort <ORDER>] [--hist <HIST>] [--title]
6-
[--rank <RANK>] [--taxrule <TAXRULE>] [--cluster <GROUPS>...]
6+
[--rank <RANK>] [--taxrule <TAXRULE>] [--label <GROUPS>...]
77
[--h|--help]
88
99
Options:
@@ -27,8 +27,8 @@
2727
(Supported: species, genus, family, order, phylum, superkingdom)
2828
--taxrule <TAXRULE> Taxrule which has been used for computing taxonomy
2929
(Supported: bestsum, bestsumorder) [default: bestsum]
30-
--cluster <GROUPS>... Cluster taxonomic groups together,
31-
e.g. "Contaminants=Actinobacteria,Proteobacteria"
30+
--label <GROUPS>... Relabel taxonomic groups,
31+
e.g. "Bacteria=Actinobacteria,Proteobacteria"
3232
"""
3333

3434
from __future__ import division
@@ -59,7 +59,7 @@
5959
hist_type = args['--hist']
6060
plot_title = args['--title']
6161
ignore_contig_length = args['--x']
62-
clusters = args['--cluster']
62+
labels = args['--label']
6363

6464
# Does blobdb_f exist ?
6565
if not isfile(blobdb_f):
@@ -79,19 +79,19 @@
7979
if taxrule not in TAXRULES:
8080
BtLog.error('8', taxrule)
8181

82-
# compute clusters if supplied
83-
cluster_d = {}
84-
if (clusters):
82+
# compute labels if supplied
83+
label_d = {}
84+
if (labels):
8585
try:
86-
for cluster in clusters:
86+
for cluster in labels:
8787
name, groups = cluster.split("=")
8888
for group in groups.split(","):
8989
if (group):
90-
if group in cluster_d:
90+
if group in label_d:
9191
BtLog.error('17', group)
92-
cluster_d[group] = name
92+
label_d[group] = name
9393
except:
94-
BtLog.error('16', clusters)
94+
BtLog.error('16', labels)
9595

9696
# Load BlobDb
9797
print BtLog.status_d['9'] % blobdb_f
@@ -107,7 +107,7 @@
107107
BtLog.error('11', taxrule, blobDB.taxrules)
108108

109109
# blobDB.getArrays(rank, c_index, min_length, multiplot, hide_nohits, out_prefix, max_taxa_plot, sort_order, taxrule, hist_type, plot_title)
110-
data_array, cov_arrays, summary_dict = blobDB.getArrays(rank, min_length, hide_nohits, taxrule, c_index, cluster_d)
110+
data_array, cov_arrays, summary_dict = blobDB.getArrays(rank, min_length, hide_nohits, taxrule, c_index, label_d)
111111
plot_order = BtPlot.getPlotOrder(summary_dict, sort_order, max_taxa_plot)
112112
colour_dict = BtPlot.getColourDict(plot_order)
113113
min_cov, max_cov = BtPlot.getMinMaxCov(cov_arrays)
@@ -121,8 +121,8 @@
121121
out_f = "%s.%s" % (out_prefix, out_f)
122122
if c_index:
123123
out_f = "%s.%s" % (out_f, "c_index")
124-
if clusters:
125-
out_f = "%s.%s" % (out_f, "cluster_" + "_".join(set([name for name in cluster_d.values()])))
124+
if labels:
125+
out_f = "%s.%s" % (out_f, "label_" + "_".join(set([name for name in label_d.values()])))
126126
out_f = "%s.%s.%s" % (out_f, min_length, taxrule)
127127
BtPlot.plot(data_array, cov_array, summary_dict, plot_order, colour_dict, min_cov, max_cov, multiplot, hist_type, plot_title, out_f, ignore_contig_length, info)
128128
info = 0

stats.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)