Skip to content

Commit

Permalink
Merge pull request #117 from KoslickiLab/add_version
Browse files Browse the repository at this point in the history
Add version
  • Loading branch information
dkoslicki authored Mar 19, 2024
2 parents 6f608c9 + e140f5f commit 5791210
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 20 deletions.
49 changes: 47 additions & 2 deletions yacht/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import sys

from . import (
download_default_ref_db,
Expand All @@ -12,9 +13,48 @@
)
from .utils import __version__

# Custom help action
class CustomHelpAction(argparse.Action):
def __init__(self, option_strings, dest, **kwargs):
super(CustomHelpAction, self).__init__(option_strings=option_strings, dest=dest, nargs=0, **kwargs)

def __call__(self, parser, namespace, values, option_string=None):
print_custom_help_exit()

def print_version():
print(f"== This is YACHT version {utils.__version__} ==")
print("== Please cite https://doi.org/10.1093/bioinformatics/btae047. ==")

def print_custom_help_exit():
print_version()
print("""
YACHT is a mathematically rigorous hypothesis test for the presence or absence of organisms
in a metagenomic sample, based on average nucleotide identity (ANI).
Usage instructions:
yacht download demo -h download YACHT demo files
yacht download default_ref_db -h download default raw reference databases
yacht download pretrained_ref_db -h download pretrained databases
yacht sketch ref -h sketch reference genomes
yacht sketch sample -h sketch metagenomics samples
yacht train -h pre-process the reference genomes
yacht run -h run the YACHT algorithm
yacht convert -h convert YACHT result to other popular output formats
Options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
""")
sys.exit()

def main():
parser = argparse.ArgumentParser(prog="yacht")
parser = argparse.ArgumentParser(prog="yacht", add_help=False)
parser.add_argument("-v", "--version", action="store_true", help="show program's version number and exit")
parser.add_argument("-h", "--help", action=CustomHelpAction, help="show this help message and exit")
subparsers = parser.add_subparsers(dest="command")

# Train command
Expand Down Expand Up @@ -85,10 +125,15 @@ def main():
sketch_sample_parser.set_defaults(func=sketch_sample.main)

args = parser.parse_args()

if args.version:
print_version()
sys.exit()

if "func" in args:
args.func(args)
else:
parser.print_help()
print_custom_help_exit()


if __name__ == "__main__":
Expand Down
3 changes: 1 addition & 2 deletions yacht/download_default_ref_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
from .utils import create_output_folder, check_download_args
# Import global variables
from .utils import BASE_URL, __version__
from .utils import BASE_URL

# Configure Loguru logger
logger.remove()
Expand All @@ -16,7 +16,6 @@


def add_arguments(parser):
parser.add_argument("--version", action="version", version=f"YACHT {__version__}")
parser.add_argument("--database", choices=["genbank", "gtdb"], required=True)
parser.add_argument(
"--db_version",
Expand Down
3 changes: 1 addition & 2 deletions yacht/download_demofiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import argparse
from loguru import logger
# Import global variables
from .utils import GITHUB_API_URL, GITHUB_RAW_URL, __version__
from .utils import GITHUB_API_URL, GITHUB_RAW_URL

# Configure Loguru logger
logger.remove()
Expand All @@ -17,7 +17,6 @@


def add_arguments(parser):
parser.add_argument("--version", action="version", version=f"YACHT {__version__}")
parser.add_argument("--outfolder", help="Output folder.", default="demo")


Expand Down
3 changes: 1 addition & 2 deletions yacht/download_pretrained_ref_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import zipfile
from .utils import create_output_folder, check_download_args
# Import global variables
from .utils import ZENODO_COMMUNITY_URL, __version__
from .utils import ZENODO_COMMUNITY_URL

# Configure Loguru logger
logger.remove()
Expand All @@ -20,7 +20,6 @@


def add_arguments(parser):
parser.add_argument("--version", action="version", version=f"YACHT {__version__}")
parser.add_argument("--database", choices=["genbank", "gtdb"], required=True)
parser.add_argument(
"--db_version", choices=["genbank-2022.03", "rs214"], required=True
Expand Down
3 changes: 0 additions & 3 deletions yacht/make_training_data_from_sketches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@


def add_arguments(parser):
parser.add_argument(
"--version", action="version", version=f"YACHT {utils.__version__}"
)
parser.add_argument(
"--ref_file",
help="Location of the Sourmash signature database file. "
Expand Down
3 changes: 0 additions & 3 deletions yacht/run_YACHT.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@


def add_arguments(parser):
parser.add_argument(
"--version", action="version", version=f"YACHT {utils.__version__}"
)
parser.add_argument(
"--json",
type=str,
Expand Down
2 changes: 0 additions & 2 deletions yacht/sketch_ref_genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path
from loguru import logger
# Import global variables
from .utils import __version__

# Configure Loguru logger
logger.remove()
Expand All @@ -16,7 +15,6 @@


def add_arguments(parser):
parser.add_argument("--version", action="version", version=f"YACHT {__version__}")
parser.add_argument("--infile", help="Input file or folder path.", required=True)
parser.add_argument("--kmer", type=int, help="K-mer size.", default=31)
parser.add_argument("--scaled", type=int, help="Scaled factor.", default=1000)
Expand Down
2 changes: 0 additions & 2 deletions yacht/sketch_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from loguru import logger

# Import global variables
from .utils import __version__

# Configure Loguru logger
logger.remove()
Expand All @@ -18,7 +17,6 @@


def add_arguments(parser):
parser.add_argument("--version", action="version", version=f"YACHT {__version__}")
parser.add_argument(
"--infile",
nargs="+",
Expand Down
3 changes: 1 addition & 2 deletions yacht/standardize_yacht_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import biom
import argparse
from biom.util import biom_open
from .utils import get_cami_profile, __version__
from .utils import get_cami_profile
from collections import OrderedDict
from loguru import logger

Expand All @@ -23,7 +23,6 @@


def add_arguments(parser):
parser.add_argument("--version", action="version", version=f"YACHT {__version__}")
parser.add_argument(
"--yacht_output",
type=str,
Expand Down

0 comments on commit 5791210

Please sign in to comment.