Skip to content

Commit

Permalink
Add handling of empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
boasvdp committed Feb 23, 2022
1 parent 895e4ca commit 05901b6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions extract_genes_abricate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
1 change: 1 addition & 0 deletions test/input/test_empty.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#FILE SEQUENCE START END STRAND GENE COVERAGE COVERAGE_MAP GAPS %COVERAGE %IDENTITY DATABASE ACCESSION PRODUCT RESISTANCE

0 comments on commit 05901b6

Please sign in to comment.