From 05901b6b30bf41d0d7064800622297bce5c729fe Mon Sep 17 00:00:00 2001 From: boasvdp Date: Wed, 23 Feb 2022 19:38:29 +0100 Subject: [PATCH] Add handling of empty files --- .github/workflows/main.yml | 2 ++ extract_genes_abricate.py | 13 ++++++++----- test/input/test_empty.tsv | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 test/input/test_empty.tsv diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b1b5063..de462c8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,6 +56,8 @@ jobs: # Testing with flanking sequences which run off the contig end python extract_genes_abricate.py -a test/input/flanking.tsv -g test/genomes -o test/out_flanking_15bp --flanking --flanking-bp 15 cmp test/correct/correct_flanking_15bp.out test/out_flanking_15bp/flanking_blaCTX-M-15.out + # Test with empty file + python extract_genes_abricate.py -a test/input/test_empty.tsv -g test/genomes -o test/out_empty - name: Tests with combined ABRicate files from multiple genomes run: | # Normal gene extraction should work for files with multiple genomes diff --git a/extract_genes_abricate.py b/extract_genes_abricate.py index 7a730c5..5b19467 100644 --- a/extract_genes_abricate.py +++ b/extract_genes_abricate.py @@ -220,12 +220,15 @@ def main(args): logging.debug(f"Calling function main") check_outdir(args.outdir) df = read_abricatefile(args.abricatefile, args.csv) - if args.genecluster == False: - logging.debug(f"Executing main_genes for extraction of single genes") - main_genes(df, args) + if df.shape[0] > 0: + if args.genecluster == False: + logging.debug(f"Executing main_genes for extraction of single genes") + main_genes(df, args) + else: + logging.debug(f"Executing main_genecluster for extraction of gene clusters") + main_genecluster(df, args) else: - logging.debug(f"Executing main_genecluster for extraction of gene clusters") - main_genecluster(df, args) + logging.warning(f"No hits found in {args.abricatefile}, outputting empty directory {args.outdir}") if __name__ == '__main__': parser = argparse.ArgumentParser(description='Extract genes from genes based on ABRicate output.') diff --git a/test/input/test_empty.tsv b/test/input/test_empty.tsv new file mode 100644 index 0000000..9423b57 --- /dev/null +++ b/test/input/test_empty.tsv @@ -0,0 +1 @@ +#FILE SEQUENCE START END STRAND GENE COVERAGE COVERAGE_MAP GAPS %COVERAGE %IDENTITY DATABASE ACCESSION PRODUCT RESISTANCE