Skip to content

Commit 91f2ac2

Browse files
authored
Better handling of errors while building from pubMLST (#31)
Colorized output! Mostly addresses #30
1 parent 06a0e0d commit 91f2ac2

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from os import path
88
here = path.abspath(path.dirname(__file__))
99
long_description="Fast k-mer based tool for alignment and assembly-free multi locus sequence typing (MLST) directly from genome sequencing reads."
10-
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
10+
with open(path.join(here, 'README.rst')) as f:
1111
long_description = f.read()
1212

1313
setup(
1414
name = 'stringMLST',
1515
scripts = ['stringMLST.py'],
16-
version = '0.3.6.3',
16+
version = '0.4',
1717
description = 'Fast k-mer based tool for alignment and assembly-free multi locus sequence typing (MLST) directly from genome sequencing reads.',
1818
long_description=long_description,
1919
author = 'Jordan Lab',

stringMLST.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
except ImportError:
1717
from urllib import urlopen, urlretrieve
1818
import argparse
19-
version = """ stringMLST v0.3.6.3 (updated : April 18, 2017) """
19+
version = """ stringMLST v0.4 (updated : May 17, 2017) """
2020
"""
2121
2222
stringMLST free for academic users and requires permission before any commercial
@@ -281,19 +281,30 @@ def get_links(speciesName,schemes):
281281
# Input : URLs from get_links
282282
# Output : Downloads files and builds database
283283
#############################################################
284-
def get_files(profileURL):
284+
def get_files(profileURL,species):
285285
with open(config, "w") as configFile:
286286
configFile.write("[loci]\n")
287287
for file in loci:
288288
localFile = filePrefix + "_" + file + ".tfa"
289-
localFfile, headers = urlretrieve(loci[file],localFile)
289+
try:
290+
localFfile, headers = urlretrieve(loci[file],localFile)
291+
except:
292+
print( '\033[91m' + "There was an error downloading " + file + '\033[0m')
293+
pass
290294
configFile.write(file + "\t" + filePrefix + "_" + file + ".tfa\n")
291295
localFile = filePrefix + "_profile.txt"
292296
localFile, headers = urlretrieve(profileURL,localFile)
293297
configFile.write("[profile]\n")
294298
configFile.write("profile\t" + filePrefix + "_profile.txt\n")
295299
configFile.close()
296-
makeCustomDB(config,k,filePrefix)
300+
try:
301+
makeCustomDB(config,k,filePrefix)
302+
except:
303+
print( '\033[91m' + "Failed to create database " + schemes[species] + '\033[0m' )
304+
pass
305+
else:
306+
print("\t" + '\033[92m' + "Database ready for " + schemes[species] + '\033[0m')
307+
print( "\t" + filePrefix)
297308
############################################################
298309
# Function : batchTool
299310
# Input : Directory name, paired or single, k value
@@ -1382,7 +1393,7 @@ def checkParams(buildDB, predict, config, k, listMode, list, batch, dir, fastq1,
13821393
"orientia-tsutsugamushi" : "Orientia tsutsugamushi",
13831394
"ornithobacterium-rhinotracheale" : "Ornithobacterium rhinotracheale",
13841395
"paenibacillus-larvae" : "Paenibacillus larvae",
1385-
#"pasteurella-multocida1" : "Pasteurella multocida#1",
1396+
"pasteurella-multocida1" : "Pasteurella multocida#1",
13861397
"pasteurella-multocida2" : "Pasteurella multocida#2",
13871398
"pediococcus-pentosaceus" : "Pediococcus pentosaceus",
13881399
"photobacterium-damselae" : "Photobacterium damselae",
@@ -1594,15 +1605,17 @@ def checkParams(buildDB, predict, config, k, listMode, list, batch, dir, fastq1,
15941605
print("Using a kmer size of " + str(k) + " for all databases.")
15951606
for key in sorted(schemes.keys()):
15961607
filePrefix = str(dbPrefix.rsplit("/",1)[0]) + "/" + key
1597-
print ("Preparing: " + schemes[key] + " ( " + filePrefix + "/" + key + "_" +str(k) + " )")
1608+
print ('\033[1m' + "Preparing: " + schemes[key] + '\033[0m')
1609+
# Move the rest of this informational message into the download handler
1610+
# + " ( " + filePrefix + "/" + key + "_" +str(k) + " )")
15981611
try:
15991612
os.makedirs(filePrefix)
16001613
except OSError:
16011614
pass
16021615
filePrefix = filePrefix + "/" + key
16031616
config = filePrefix + "_config.txt"
16041617
profileURL = get_links(key,schemes)
1605-
get_files(profileURL)
1618+
get_files(profileURL,key)
16061619
else:
16071620
try:
16081621
os.makedirs(dbPrefix.rsplit("/",1)[0])
@@ -1621,9 +1634,8 @@ def checkParams(buildDB, predict, config, k, listMode, list, batch, dir, fastq1,
16211634
filePrefix = dbPrefix
16221635
config = filePrefix + "_config.txt"
16231636
profileURL = get_links(species,schemes)
1624-
get_files(profileURL)
1625-
print("Database ready for " + schemes[species])
1626-
print( filePrefix)
1637+
get_files(profileURL,species)
1638+
16271639
else:
16281640
print(helpTextSmall)
16291641
print("Error: Please select the mode: buildDB (for database building) or predict (for ST discovery) module")

0 commit comments

Comments
 (0)