From 4ef852623b9174bcc22d14d8bfecab4fdaa707f3 Mon Sep 17 00:00:00 2001 From: Kirill Bessonov Date: Tue, 30 Jul 2024 14:50:02 -0400 Subject: [PATCH] Fixed pytest small error with test_emtpy_BLAST_antigen_hits --- ectyper/ectyper.py | 2 +- ectyper/predictionFunctions.py | 12 +++++++++--- test/test_complex_inputs.py | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ectyper/ectyper.py b/ectyper/ectyper.py index 906c873..148ff1e 100644 --- a/ectyper/ectyper.py +++ b/ectyper/ectyper.py @@ -196,7 +196,7 @@ def run_program(): # Add empty rows for genomes without a blast result or non-E.coli samples that did not undergo typing final_predictions = predictionFunctions.add_non_predicted( raw_genome_files, predictions_dict, other_genomes_dict, filesnotfound_dict, ecoli_genomes_dict) - print(final_predictions) + for sample in final_predictions.keys(): final_predictions[sample]["database"] = "v"+ectyperdb_dict["version"] + " (" + ectyperdb_dict["date"] + ")" diff --git a/ectyper/predictionFunctions.py b/ectyper/predictionFunctions.py index 0721bad..ea16019 100644 --- a/ectyper/predictionFunctions.py +++ b/ectyper/predictionFunctions.py @@ -221,11 +221,17 @@ def predict_pathotype_and_shiga_toxin_subtype(ecoli_genome_files_dict, other_gen "-out", f"{temp_dir}/blast_pathotype_result.txt", "-outfmt", "6 qseqid qlen sseqid length pident sstart send sframe slen qcovhsp bitscore sseq" ] - LOG.debug(f"BLASTN results on pathotype database written to {temp_dir}/blast_pathotype_result.txt ...") - cmd_status = subprocess_util.run_subprocess(cmd) + cmd_status = subprocess_util.run_subprocess(cmd) + if cmd_status.returncode == 0: + LOG.info(f"BLASTN on pathotype database for {g} was successful and results written to {temp_dir}/blast_pathotype_result.txt ...") + else: + LOG.critical(f"BLASTn against pathotype database failed with error code {cmd_status.returncode} and pathotype results for {g} would NOT be available. Skipping pathotyping ...") + continue + + if os.stat(f'{temp_dir}/blast_pathotype_result.txt').st_size == 0: - LOG.warning(f"No pathotype signatures found for sample {g} as pathotype BLAST results file {temp_dir}/blast_pathotype_result.txt is empty. Skipping ...") + LOG.warning(f"No pathotype signatures found for sample {g} as pathotype BLAST results file {temp_dir}/blast_pathotype_result.txt is empty. Skipping pathotyping...") predictions_pathotype_dict[g]={field:'-' for field in definitions.PATHOTYPE_TOXIN_FIELDS} predictions_pathotype_dict[g]['pathotype']= ['ND'] continue diff --git a/test/test_complex_inputs.py b/test/test_complex_inputs.py index 59568c7..e3e7e8b 100644 --- a/test/test_complex_inputs.py +++ b/test/test_complex_inputs.py @@ -52,7 +52,7 @@ def test_emtpy_BLAST_antigen_hits(tmpdir): with open(file=ectyper.definitions.SEROTYPE_ALLELE_JSON) as fp: ectyperdb_dict = json.load(fp) alleles_fasta_file = ectyper.create_alleles_fasta_file(tmpdir, ectyperdb_dict) - db_prediction_dict = ectyper.genome_group_prediction([args.input], alleles_fasta_file, args, tmpdir, ectyperdb_dict) + db_prediction_dict = ectyper.genome_group_prediction(args.input, alleles_fasta_file, args, tmpdir, ectyperdb_dict) assert db_prediction_dict == {} def test_invalid_fasta():