Skip to content

Commit

Permalink
getmlst.py added options
Browse files Browse the repository at this point in the history
- Added the requirement to add an output folder, for MLST database storage, so that files don't just get stored in home directory
- Added the 'delimiter' output file to make it easier for me to use srst2 in a bash script I was putting together
NOTE: I have zero experience with python, so there may be errors, but it's worked in my limited testing to date
  • Loading branch information
alegione authored Mar 22, 2017
1 parent 8a854ad commit f1cd377
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions scripts/getmlst.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def parse_args():
parser.add_argument('--force_scheme_name',
action="store_true",
default = False,
help = 'Flage to force downloading of specific scheme name (e.g. "Clostridium difficile")')
help = 'Flag to force downloading of specific scheme name (e.g. "Clostridium difficile")')
parser.add_argument('--output',
type=str,
required=True,
help='Prefix for srst2 output files')

return parser.parse_args()

Expand Down Expand Up @@ -145,12 +149,20 @@ def main():
os.remove(filename)

# output information for the single matching species
species_all_fasta_filename = species_name_underscores + '.fasta'
if not os.path.exists(args.output):
os.makedirs(args.output)

species_all_fasta_filename = args.output + species_name_underscores + '.fasta'
species_all_fasta_file = open(species_all_fasta_filename, 'w')
log_filename = "mlst_data_download_{}_{}.log".format(species_name_underscores, species_info.retrieved)


delimiter_filename = args.output + species_name_underscores + '.delimiter'
delimiter_file = open(delimiter_filename, 'w')

log_filename = args.output + "mlst_data_download_{}_{}.log".format(species_name_underscores, species_info.retrieved)
log_file = open(log_filename, "w")
profile_path = urlparse(species_info.profiles_url).path
profile_filename = profile_path.split('/')[-1]
profile_filename = args.output + profile_path.split('/')[-1]
log_file.write("definitions: {}\n".format(profile_filename))
log_file.write("{} profiles\n".format(species_info.profiles_count))
log_file.write("sourced from: {}\n\n".format(species_info.profiles_url))
Expand All @@ -161,7 +173,7 @@ def main():
profile_doc.close()
for locus in species_info.loci:
locus_path = urlparse(locus.url).path
locus_filename = locus_path.split('/')[-1]
locus_filename = args.output + locus_path.split('/')[-1]
log_file.write("locus {}\n".format(locus.name))
log_file.write(locus_filename + '\n')
log_file.write("Sourced from {}\n\n".format(locus.url))
Expand Down Expand Up @@ -192,7 +204,7 @@ def main():
print "--mlst_definitions " + format(profile_filename),
print "--mlst_delimiter '" + m[1] + "'"
print

delimiter_file.write("Suggested mlst delimiter " + m[1] + "\n")

if __name__ == '__main__':
main()

0 comments on commit f1cd377

Please sign in to comment.