Skip to content

Commit 477b17d

Browse files
Dom LaetschDom Laetsch
authored andcommitted
CodeMassage
- Added Try/Except to Nodes.dmp/Names.dmp parsing - Made error message more fitting
1 parent 446d7d6 commit 477b17d

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

lib/BtIO.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -251,26 +251,32 @@ def getNodesDB(**kwargs):
251251
print BtLog.status_d['3'] % (kwargs['nodes'], kwargs['names'])
252252
nodesDB = {}
253253
nodes_count = 0
254-
with open(kwargs['nodes']) as fh:
255-
for line in fh:
256-
nodes_col = line.split("\t")
257-
node = {}
258-
node_id = nodes_col[0]
259-
node['parent'] = nodes_col[2]
260-
node['rank'] = nodes_col[4]
261-
nodesDB[node_id] = node
262-
nodes_count += 1
263-
with open(kwargs['names']) as fh:
264-
for line in fh:
265-
names_col = line.split("\t")
266-
if names_col[6] == "scientific name":
267-
nodesDB[names_col[0]]['name'] = names_col[2]
268-
nodesDB_f = kwargs['nodesDB']
269-
nodesDB['nodes_count'] = nodes_count
254+
try:
255+
with open(kwargs['nodes']) as fh:
256+
for line in fh:
257+
nodes_col = line.split("\t")
258+
node = {}
259+
node_id = nodes_col[0]
260+
node['parent'] = nodes_col[2]
261+
node['rank'] = nodes_col[4]
262+
nodesDB[node_id] = node
263+
nodes_count += 1
264+
with open(kwargs['names']) as fh:
265+
for line in fh:
266+
names_col = line.split("\t")
267+
if names_col[6] == "scientific name":
268+
nodesDB[names_col[0]]['name'] = names_col[2]
269+
nodesDB_f = kwargs['nodesDB']
270+
nodesDB['nodes_count'] = nodes_count
271+
except:
272+
BtLog.error('3')
270273
elif (kwargs['nodesDB']):
271-
print BtLog.status_d['4'] % (kwargs['nodesDB'])
272-
nodesDB = readNodesDB(kwargs['nodesDB'])
273-
nodesDB_f = kwargs['nodesDB']
274+
try:
275+
print BtLog.status_d['4'] % (kwargs['nodesDB'])
276+
nodesDB = readNodesDB(kwargs['nodesDB'])
277+
nodesDB_f = kwargs['nodesDB']
278+
except:
279+
BtLog.error('3')
274280
else:
275281
BtLog.error('3')
276282
return nodesDB, nodesDB_f

lib/BtLog.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55
File : BtLog.py
66
Version : 0.1
7-
Author : Dominik R. Laetsch, dominik.laetsch at gmail dot com
7+
Author : Dominik R. Laetsch, dominik.laetsch at gmail dot com
88
Bugs : ?
99
To do : ?
1010
"""
@@ -34,7 +34,7 @@ def progress(iteration, steps, max_value):
3434
'0' : '[ERROR:0]\t: File %s does not exist.',
3535
'1' : '[ERROR:1]\t: Please provide coverage information.',
3636
'2' : '[ERROR:2]\t: Assembly type is not valid (%s).',
37-
'3' : '[ERROR:3]\t: nodesDB ("--db") or names.dmp/nodes.dmp ("--nodes", "--names") not specified.',
37+
'3' : '[ERROR:3]\t: nodesDB ("--db") or names.dmp/nodes.dmp ("--nodes", "--names") could not be read.',
3838
'4' : '[ERROR:4]\t: BlobDB.parseFasta() - no sequences found. Check FASTA file.',
3939
'5' : '[ERROR:5]\t: Sequence header %s is not unique.',
4040
'6' : '[ERROR:6]\t: BlobDB.readBam() - sequence header %s in %s was not in FASTA.',
@@ -61,7 +61,7 @@ def progress(iteration, steps, max_value):
6161
}
6262

6363
warn_d = {
64-
'0' : '[WARN]\t: No tax files specified.',
64+
'0' : '[WARN]\t: No tax files specified.',
6565
'1' : '[WARN]\t: %s not in colour file %s ...',
6666
'2' : '[WARN]\t: %s in file %s is not part of the assembly',
6767
'3' : '[WARN]\t: samtools flagstat reported %s mapped reads, %s mapped reads were parsed',
@@ -87,5 +87,5 @@ def progress(iteration, steps, max_value):
8787
'0' : '\t[INFO]\t: %s : sequences = %s, span = %s MB, N50 = %s nt'
8888
}
8989

90-
if __name__ == "__main__":
91-
pass
90+
if __name__ == "__main__":
91+
pass

0 commit comments

Comments
 (0)