Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
maxibor committed Jul 24, 2024
2 parents e134278 + 04f18fa commit 0ac7e43
Show file tree
Hide file tree
Showing 46 changed files with 1,399 additions and 536 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
docs/build/
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
10 changes: 10 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: pip install .


2 changes: 1 addition & 1 deletion AMDirT/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.4"
__version__ = "1.6.1"
2 changes: 2 additions & 0 deletions AMDirT/autofill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def run_autofill(accession, table_name=None, schema=None, dataset=None, sample_o
lib_out[col] = None
lib_out = lib_out[libraries_df.columns]
lib_out = lib_out.loc[:,~lib_out.columns.duplicated()].copy()
lib_out['read_count'] = lib_out['read_count'].str.replace(",", "",
regex=False)
lib_out = lib_out.astype(libraries_df.dtypes.to_dict())

if library_output:
Expand Down
138 changes: 109 additions & 29 deletions AMDirT/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,38 @@
from AMDirT.validate import run_validation
from AMDirT.viewer import run_app
from AMDirT.convert import run_convert
from AMDirT.core import get_json_path
from AMDirT.core import get_json_path, get_amdir_tags, get_latest_tag
from AMDirT.autofill import run_autofill
from AMDirT.merge import merge_new_df
from AMDirT.download import download as download_amdir
from json import load


class MutuallyExclusiveOption(click.Option):
# Credits goes to Stan Chang for this code snippet
# https://gist.github.com/stanchan/bce1c2d030c76fe9223b5ff6ad0f03db

def __init__(self, *args, **kwargs):
self.mutually_exclusive = set(kwargs.pop("mutually_exclusive", []))
help = kwargs.get("help", "")
if self.mutually_exclusive:
ex_str = ", ".join(self.mutually_exclusive)
kwargs["help"] = help + (
" NOTE: This argument is mutually exclusive with "
" arguments: [" + ex_str + "]."
)
super(MutuallyExclusiveOption, self).__init__(*args, **kwargs)

def handle_parse_result(self, ctx, opts, args):
if self.mutually_exclusive.intersection(opts) and self.name in opts:
raise click.UsageError(
"Illegal usage: `{}` is mutually exclusive with "
"arguments `{}`.".format(self.name, ", ".join(self.mutually_exclusive))
)

return super(MutuallyExclusiveOption, self).handle_parse_result(ctx, opts, args)


def get_table_list():
json_path = get_json_path()
with open(json_path, "r") as f:
Expand Down Expand Up @@ -110,6 +136,20 @@ def viewer(ctx, no_args_is_help=True, **kwargs):
type=click.Path(exists=True),
help="(Optional) JSON file listing AncientMetagenomeDir tables",
)
@click.option(
"--libraries",
type=click.Path(readable=True, file_okay=True, dir_okay=False, exists=True),
help=("(Optional) Path to a pre-filtered libraries table"),
cls=MutuallyExclusiveOption,
mutually_exclusive=["librarymetadata"],
)
@click.option(
"--librarymetadata",
is_flag=True,
help="Generate AncientMetagenomeDir libraries table of all samples in input table",
cls=MutuallyExclusiveOption,
mutually_exclusive=["libraries"],
)
@click.option(
"-o",
"--output",
Expand All @@ -123,11 +163,6 @@ def viewer(ctx, no_args_is_help=True, **kwargs):
is_flag=True,
help="Generate BibTeX file of all publications in input table",
)
@click.option(
"--librarymetadata",
is_flag=True,
help="Generate AncientMetagenomeDir libraries table of all samples in input table",
)
@click.option(
"--curl",
is_flag=True,
Expand All @@ -139,14 +174,19 @@ def viewer(ctx, no_args_is_help=True, **kwargs):
help="Generate bash script with Aspera-based download commands for all libraries of samples in input table",
)
@click.option(
"--eager",
"--fetchngs",
is_flag=True,
help="Convert filtered samples and libraries tables to eager input tables",
help="Convert filtered samples and libraries tables to nf-core/fetchngs input tables",
)
@click.option(
"--fetchngs",
"--sratoolkit",
is_flag=True,
help="Convert filtered samples and libraries tables to nf-core/fetchngs input tables",
help="Generate bash script with SRA Toolkit fasterq-dump based download commands for all libraries of samples in input table",
)
@click.option(
"--eager",
is_flag=True,
help="Convert filtered samples and libraries tables to eager input tables",
)
@click.option(
"--ameta",
Expand All @@ -167,6 +207,9 @@ def viewer(ctx, no_args_is_help=True, **kwargs):
def convert(ctx, no_args_is_help=True, **kwargs):
"""\b
Converts filtered samples and libraries tables to eager, ameta, taxprofiler, and fetchNGS input tables
Note: When supplying a pre-filtered libraries table with `--libraries`, the corresponding sample table is still required!
\b
SAMPLES: path to filtered AncientMetagenomeDir samples tsv file
TABLE_NAME: name of table to convert
Expand All @@ -178,26 +221,27 @@ def convert(ctx, no_args_is_help=True, **kwargs):
# Autofill tool #
#################


@cli.command()
@click.argument("accession", type=str, nargs=-1)
@click.option(
"-n",
"--table_name",
"--table_name",
type=click.Choice(get_table_list()),
default='ancientmetagenome-hostassociated',
show_default=True
default="ancientmetagenome-hostassociated",
show_default=True,
)
@click.option(
"-l",
"--library_output",
type=click.Path(writable=True),
help="path to library output table file"
help="path to library output table file",
)
@click.option(
"-s",
"--sample_output",
type=click.Path(writable=True),
help="path to sample output table file"
help="path to sample output table file",
)
@click.pass_context
def autofill(ctx, no_args_is_help=True, **kwargs):
Expand All @@ -219,31 +263,26 @@ def autofill(ctx, no_args_is_help=True, **kwargs):
@click.argument("dataset", type=click.Path(exists=True))
@click.option(
"-n",
"--table_name",
"--table_name",
type=click.Choice(get_table_list()),
default='ancientmetagenome-hostassociated',
show_default=True
default="ancientmetagenome-hostassociated",
show_default=True,
)
@click.option(
"-t",
"--table_type",
type=click.Choice(['samples', 'libraries']),
default='libraries',
show_default=True
)
@click.option(
"-m",
"--markdown",
is_flag=True,
help="Output is in markdown format"
"--table_type",
type=click.Choice(["samples", "libraries"]),
default="libraries",
show_default=True,
)
@click.option("-m", "--markdown", is_flag=True, help="Output is in markdown format")
@click.option(
"-o",
"--outdir",
type=click.Path(writable=True),
default=".",
show_default=True,
help="path to sample output table file"
help="path to sample output table file",
)
@click.pass_context
def merge(ctx, no_args_is_help=True, **kwargs):
Expand All @@ -255,5 +294,46 @@ def merge(ctx, no_args_is_help=True, **kwargs):
"""
merge_new_df(**kwargs, **ctx.obj)


@cli.command()
@click.option(
"-t",
"--table",
help="AncientMetagenomeDir table to download",
type=click.Choice(get_table_list()),
default="ancientmetagenome-hostassociated",
show_default=True,
)
@click.option(
"-y",
"--table_type",
help="Type of table to download",
type=click.Choice(["samples", "libraries"]),
default="samples",
show_default=True,
)
@click.option(
"-r",
"--release",
help="Release tag to download",
type=click.Choice(get_amdir_tags()),
default=get_latest_tag(get_amdir_tags()),
show_default=True,
)
@click.option(
"-o",
"--output",
help="Output directory",
type=click.Path(writable=True),
default=".",
show_default=True,
)
def download(no_args_is_help=True, **kwargs):
"""\b
Download a table from the AMDirT repository
"""
download_amdir(**kwargs)


if __name__ == "__main__":
cli()
Loading

0 comments on commit 0ac7e43

Please sign in to comment.