Skip to content

Commit

Permalink
[translate] separate out VCF-specific arguments
Browse files Browse the repository at this point in the history
This helps readability of the --help content. We enforce this behaviour
by adding a check in the code following the example in `augur ancestral`
  • Loading branch information
jameshadfield committed Dec 19, 2023
1 parent 112e73a commit efb43b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

* translate: Improvements to command line arguments. [#1348][] (@jameshadfield)
* `--tree` and `--ancestral-sequences` are now required arguments.
* separate VCF-only arguments into their own group

[#1344]: https://github.com/nextstrain/augur/pull/1344
[#1348]: https://github.com/nextstrain/augur/pull/1348
Expand Down
22 changes: 20 additions & 2 deletions augur/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .io.vcf import write_VCF_translation
from .utils import read_node_data, load_features, write_json, get_json_name
from treetime.vcf_utils import read_vcf
from augur.errors import AugurError

class MissingNodeError(Exception):
pass
Expand Down Expand Up @@ -326,10 +327,25 @@ def register_parser(parent_subparsers):
parser.add_argument('--alignment-output', type=str, help="write out translated gene alignments. "
"If a VCF-input, a .vcf or .vcf.gz will be output here (depending on file ending). If fasta-input, specify the file name "
"like so: 'my_alignment_%%GENE.fasta', where '%%GENE' will be replaced by the name of the gene")
parser.add_argument('--vcf-reference-output', type=str, help="fasta file where reference sequence translations for VCF input will be written")
parser.add_argument('--vcf-reference', type=str, help='fasta file of the sequence the VCF was mapped to')
vcf_only = parser.add_argument_group(
title="VCF specific",
description="These arguments are only applicable if the input (--ancestral-sequences) is in VCF format."
)
vcf_only.add_argument('--vcf-reference', type=str, help='fasta file of the sequence the VCF was mapped to')
vcf_only.add_argument('--vcf-reference-output', type=str, help="fasta file where reference sequence translations for VCF input will be written")

return parser

def check_arg_combinations(args, is_vcf):
"""
Check that provided arguments are compatible.
Where possible we use argparse built-ins, but they don't cover everything we want to check.
This checking shouldn't be used by downstream code to assume arguments exist, however by checking for
invalid combinations up-front we can exit quickly.
"""
if not is_vcf and (args.vcf_reference or args.vcf_reference_output):
raise AugurError("Arguments '--vcf-reference' and/or '--vcf-reference-output' are only applicable if the input ('--ancestral-sequences') is VCF")


def run(args):
## read tree and data, if reading data fails, return with error code
Expand Down Expand Up @@ -362,6 +378,8 @@ def run(args):
if 'sequence' in v:
sequences[k] = v['sequence']

check_arg_combinations(args, is_vcf)

## load features; only requested features if genes given
features = load_features(args.reference_sequence, genes)
if features is None:
Expand Down

0 comments on commit efb43b0

Please sign in to comment.