Skip to content

Commit f0b9b45

Browse files
Dom LaetschDom Laetsch
authored andcommitted
...
1 parent b0c5416 commit f0b9b45

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

lib/BtCore.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ def parseHits(self, hitLibs):
261261
print BtLog.status_d['1'] % (hitLib.name, hitLib.f)
262262
# only accepts format 'seqID\ttaxID\tscore'
263263
for hitDict in BtIO.readTax(hitLib.f, set(self.dict_of_blobs)):
264+
if ";" in hitDict['taxId']:
265+
hitDict['taxId'] = hitDict['taxId'].split(";")[0]
266+
print BtLog.warn['5'] % (hitDict['name'], hitLib)
264267
self.set_of_taxIds.add(hitDict['taxId'])
265268
self.dict_of_blobs[hitDict['name']].addHits(hitLib.name, hitDict)
266269

lib/BtIO.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ def readTax(infile, set_of_blobs):
220220
}
221221
if hitDict['name'] not in set_of_blobs:
222222
BtLog.error('19', hitDict['name'], infile)
223+
if hitDict['taxId'] == 'N/A':
224+
BtLog.error('22', infile)
223225
yield hitDict
224226

225227
def parseColourDict(infile):

lib/BtLog.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def progress(iteration, steps, max_value):
5050
'18' : '[ERROR:18]\t: Please provide a tax file in BLAST format.',
5151
'19' : '[ERROR:19]\t: Sequence %s in file %s is not part of the assembly.',
5252
'20' : '[ERROR:20]\t: Please add "clc_mapping_info" to you PATH variable.',
53-
'21' : '[ERROR:21]\t: refcov FILE does not seem to have the right format.'
53+
'21' : '[ERROR:21]\t: Refcov FILE does not seem to have the right format.',
54+
'22' : '[ERROR:22]\t: Tax file %s seems to have no taxids.'
5455

5556
}
5657

@@ -59,7 +60,8 @@ def progress(iteration, steps, max_value):
5960
'1' : '[WARN]\t: %s not in colour file %s ...',
6061
'2' : '[WARN]\t: %s in file %s is not part of the assembly',
6162
'3' : '[WARN]\t: samtools flagstat reported %s mapped reads, %s mapped reads were parsed',
62-
'4' : '[WARN]\t: No coverage data found in %s'
63+
'4' : '[WARN]\t: No coverage data found in %s',
64+
'5' : '[WARN]\t: Hit for sequence %s in tax file %s has multiple taxIds, only first one is used. '
6365
}
6466
status_d = {
6567
'1' : '[STATUS]\t: Parsing %s - %s',

lib/BtPlot.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ def parseRefCov(refcov_f):
5252
with open(refcov_f) as fh:
5353
for l in fh:
5454
try:
55-
cov_lib, reads_mapped_ref, reads_unmapped_ref = l.split(",")
55+
cov_lib, reads_total_ref, reads_mapped_ref = l.split(",")
5656
refcov_dict[cov_lib] = {
57-
'reads_mapped' : int(reads_mapped_ref),
58-
'reads_unmapped' : int(reads_unmapped_ref)
57+
'reads_total' : int(reads_total_ref),
58+
'reads_mapped' : int(reads_mapped_ref)
5959
}
6060
except:
6161
BtLog.error('21')
@@ -203,9 +203,9 @@ def write_stats(self):
203203
with open(out_f, 'w') as fh:
204204
for cov_lib in sorted(self.cov_libs):
205205
fh.write("# %s - %s\n" % (self.out_f, cov_lib))
206-
fh.write("{:<10}\t{:>10}{:>10}\t{:>10}\t{:<10}{:<10}\t{:<10}\t{:<5}\t{:<5}\t{:<10}\t{:<10}\t{:<10}\t{:<10}\n".format('Group', 'colour', 'count', 'visible (%)', 'span', 'visible(%)', 'n50', 'GC', 'GC (std)', 'cov_mean', 'cov_std', 'read map', 'read map (%)'))
206+
fh.write("{:<10}\t{:>10}{:>10}\t{:>10}\t{:<10}\t{:<10}\t{:<10}\t{:<5}\t{:<5}\t{:<10}\t{:<10}\t{:<10}\t{:<10}\n".format('Group', 'colour', 'count', 'visible (%)', 'span', 'visible(%)', 'n50', 'GC', 'GC (std)', 'cov_mean', 'cov_std', 'read map', 'read map (%)'))
207207
for stat in stats:
208-
fh.write("{:<10}\t{:>10}{:>10}\t{:>10}\t{:<10}{:<10}\t{:<10}\t{:<5}\t{:<5}\t{:<10}\t{:<10}\t{:<10}\t{:<10}\n".format(\
208+
fh.write("{:<10}\t{:>10}{:>10}\t{:>10}\t{:<10}\t{:<10}\t{:<10}\t{:<5}\t{:<5}\t{:<10}\t{:<10}\t{:<10}\t{:<10}\n".format(\
209209
stat['name'], stat['colour'], stat['count_total'], stat['count_visible_perc'], stat['span_total'], \
210210
stat['span_visible_perc'], stat['n50'], stat['gc_mean'], stat['gc_std'], stat['cov_mean'][cov_lib], \
211211
stat['cov_std'][cov_lib], stat['reads_mapped'][cov_lib], stat['reads_mapped_perc'][cov_lib]))
@@ -302,7 +302,7 @@ def relabel_and_colour(self, colour_f, user_labels):
302302
def plotReadCov(self, refcov_dict):
303303
mat.rcParams.update({'font.size': 14})
304304
plot_data = {}
305-
305+
306306
main_columns = 2
307307
if (refcov_dict):
308308
main_columns += 2
@@ -316,9 +316,9 @@ def plotReadCov(self, refcov_dict):
316316
reads_total = self.cov_libs_total_reads_dict[cov_lib]
317317
reads_unmapped = reads_total - self.stats['all']['reads_mapped'][cov_lib]
318318
if cov_lib in refcov_dict:
319-
reads_mapped_ref = refcov_dict[cov_lib]['reads_mapped']
320-
reads_unmapped_ref = refcov_dict[cov_lib]['reads_unmapped']
321-
reads_total_ref = reads_mapped_ref + reads_unmapped_ref
319+
reads_total_ref = refcov_dict[cov_lib]['reads_total']
320+
reads_mapped_ref = refcov_dict[cov_lib]['reads_mapped']
321+
reads_unmapped_ref = reads_total_ref - reads_mapped_ref
322322
main_plot.labels.append('Unmapped (ref)')
323323
main_plot.values.append(reads_unmapped_ref/reads_total_ref)
324324
main_plot.colours.append(DGREY)

plot.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
ps, svg, svgz, tiff) [default: png]
4141
--noblobs Omit blobplot [default: False]
4242
--noreads Omit plot of reads mapping [default: False]
43-
--refcov FILE File containing number of "mapped" and "unmapped" reads
43+
--refcov FILE File containing number of "total" and "mapped" reads
4444
per coverage file. (e.g.: bam0,900,100). If provided, info
4545
will be used in read coverage plot(s).
4646
"""
@@ -108,8 +108,9 @@
108108
else:
109109
exclude_groups = exclude_groups
110110

111+
refcov_dict = {}
111112
if (refcov_f):
112-
refcov_dict = BtPlot.parseRefCov(revcov)
113+
refcov_dict = BtPlot.parseRefCov(refcov_f)
113114

114115
# Load BlobDb
115116
print BtLog.status_d['9'] % blobdb_f
@@ -156,6 +157,8 @@
156157
out_f = "%s.%s.%s.p%s" % (title, hist_type, rank, max_group_plot)
157158
if out_prefix:
158159
out_f = "%s.%s" % (out_prefix, out_f)
160+
if ignore_contig_length:
161+
out_f = "%s.%s" % (out_f, "noscale")
159162
if c_index:
160163
out_f = "%s.%s" % (out_f, "c_index")
161164
if exclude_groups:

0 commit comments

Comments
 (0)