Skip to content

Commit

Permalink
Merge pull request #3 from rpetit3/rp3-add-gzip-support
Browse files Browse the repository at this point in the history
Add gzip support for inputs
  • Loading branch information
scwatts committed May 12, 2024
2 parents a7cce41 + 1d8da50 commit 44603a5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hicap/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def collect_orfs(fasta_fp, model_fp):

def annotate(query_fp, model_fp):
logging.debug('Annotating %s using Prodigal', query_fp)
command = 'prodigal -f sco -i %s -m -t %s'
command = 'gzip -c -d %s | prodigal -f sco -i /dev/stdin -m -t %s' if query_fp.name.endswith('gz') else 'prodigal -f sco -i %s -m -t %s'
result = utility.execute_command(command % (query_fp, model_fp))
# Prodigal includes \r from FASTAs, causing problems with the output. Remove \r here
return result.stdout.replace('\r', '')
Expand Down
2 changes: 1 addition & 1 deletion hicap/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self):

def write_outputs(locus_data, args):
# Report
prefix = args.query_fp.stem
prefix = pathlib.Path(args.query_fp.stem).stem if args.query_fp.name.endswith('gz') else args.query_fp.stem
output_report_fp = pathlib.Path(args.output_dir, '%s.tsv' % prefix)
fasta = utility.read_fasta(args.query_fp)
summary_data = create_summary(locus_data, fasta)
Expand Down
4 changes: 3 additions & 1 deletion hicap/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def check_dependencies():


def read_fasta(filepath):
with filepath.open('r') as fh:
import gzip

with (gzip.open(filepath, 'rt') if filepath.name.endswith('gz') else open(filepath, 'rt')) as fh:
# TODO: cleaner way to do this?
fasta = {desc: seq for desc, seq in Bio.SeqIO.FastaIO.SimpleFastaParser(fh)}
if not fasta:
Expand Down

0 comments on commit 44603a5

Please sign in to comment.