Skip to content

Commit

Permalink
Finalizing additions for #46
Browse files Browse the repository at this point in the history
  • Loading branch information
ar0ch committed Mar 5, 2019
1 parent aaaf0d5 commit fc387f9
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions stringMLST.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
#############################################################
def get_links(xmlData, savePath, speciesName):
lociList = {}
profileURL = None
for species in xmlData:
if re.search(re.escape(speciesName), species.text, re.IGNORECASE, ):
for mlst in species:
Expand All @@ -268,7 +269,21 @@ def get_links(xmlData, savePath, speciesName):
if child.tag == "loci":
for locus in child:
lociList[locus.text.rstrip()] = locus[0].text
return profileURL, lociList
if profileURL is None:
profileError = "Parsing failed: could not find profiles file"
print(profileError)
print(f"This usually means the provided species, '{speciesName}', does not exist on PubMLST")
print(f"Use `{sys.argv[0]} --getMLST --species list` to list available species")
print("Or visit PubMLST for more information:\nhttps://pubmlst.org/data/")
logging.debug(profileError)
sys.exit(1)
elif lociList == {}:
lociError = "Parsing failed: could not find allele sequences"
logging.debug(lociError)
print(lociError)
sys.exit(1)
else:
return profileURL, lociList
#############################################################
# Function : get_files
# Input : URLs from get_links
Expand Down Expand Up @@ -1310,8 +1325,9 @@ def checkParams(buildDB, predict, config, k, listMode, list, batch, dir, fastq1,
--getMLST
Identifier for getMLST module
--species= <species name>
Species name from the pubMLST schemes (use --schemes to get list of available schemes)
"all" will download and build all
Species name from the pubMLST schemes
Use "show" or "list" to list available schemes
"all" will download and build all available schemes
Optional arguments
-k = <kmer length>
Kmer size for which the db has to be formed(Default k = 35). Note the tool works best with kmer length in between 35 and 66
Expand Down Expand Up @@ -1432,7 +1448,7 @@ def checkParams(buildDB, predict, config, k, listMode, list, batch, dir, fastq1,
print("You provided '" + arg + "' for your fuzziness threshold, which is not an integer value")
exit(0)
elif opt in '--schemes':
print(", ".join(sorted(schemes.keys())))
print("The `--schemes` option has been depreciated. Please use `--species list` to see available schemes")
exit(0)
elif opt in '--getMLST':
downloadDB = True
Expand Down Expand Up @@ -1494,7 +1510,7 @@ def checkParams(buildDB, predict, config, k, listMode, list, batch, dir, fastq1,
print("To printavailable MLST Schemes use:")
print("stringMLST.py --getMLST --species show")
exit(0)
elif species == "show":
elif species == "show" or species == "list":
for species in dbRoot:
print(species.text.rstrip())
elif species == "all":
Expand All @@ -1507,7 +1523,7 @@ def checkParams(buildDB, predict, config, k, listMode, list, batch, dir, fastq1,
normSpeciesName = re.sub('[.()]', "", normSpeciesName)
print('\t\033[33m' + "INFO: normalizing name to: " + normSpeciesName + '\033[0m')
else:
normSpeciesName = species
normSpeciesName = speciesName
filePrefix = str(dbPrefix.rsplit("/", 1)[0]) + "/" + normSpeciesName
# Move the rest of this informational message into the download handler
# + " ( " + filePrefix + "/" + key + "_" +str(k) + " )")
Expand Down Expand Up @@ -1545,7 +1561,6 @@ def checkParams(buildDB, predict, config, k, listMode, list, batch, dir, fastq1,
config = filePrefix + "_config.txt"
profileURL, loci = get_links(dbRoot, filePrefix, species)
get_files(filePrefix, loci, profileURL, species)

else:
print(helpTextSmall)
print("Error: Please select the mode: buildDB (for database building) or predict (for ST discovery) module")
Expand Down

0 comments on commit fc387f9

Please sign in to comment.