Skip to main content

Add your description here

Project description

snparcher CLI

This is a proof of concept for making snparcher a CLI tool. There are a handful of reasons why we are considering moving to a CLI:

  • Easier to install via pip
  • Minimize user overhead of setting up config/samplesheet files
  • Allow direct access to QC/Postprocessing/etc modules without having to setup directory structure
  • More developer control of user experience overall.

Design

Overall this is a relatively simple CLI Python app, it takes arguments/options from the command line and then does stuff. For snparcher, "doing stuff" means running our workflow files. To achieve this, I use the entrypoint function from Snakemake itself: snakemake.cli:args_to_api (see here and here for more info.) Essentialy this function takes all the CLI args and constructs the Snakemake API and executes the workflow.

I've used typer for parsing CLI arguments for its simplicity over the stdlib argparse. typer allows you to capture all CLI arguments, including unknown ones:

@app.command(
    context_settings={"allow_extra_args": True, "ignore_unknown_options": True}
)

This allows us to pass Snakemake args (--use-conda, --profile, etc) to Snakemake while capturing arguments for our command. It also allows us to specify Snakemake arguments on behalf of the user, such as the workflow file.

So when using snparcher commands, a user will pass the snparcher command arguments first, then the Snakemake arguments/options. See below for example.

Setup

To try this out:

  1. Clone this repo:
git clone https://github.com/cademirch/snparcher-cli.git
cd snparcher-cli
  1. Create Conda env, or use uv to setup env.
  • Conda:conda create -n snparcher-cli-env "python>=3.12"
  • uv:uv venv --python 3.12 && source .venv/bin/activate
  1. Install snparcher locally and editable
  • Conda: conda activate snparcher-cli-env && pip install -e .
  • uv: uv pip install -e .
  1. Check it worked! snparcher --help

Testing

You can test the cli like so:

cd test/cli
snparcher qc --coords-file cli-coords.txt --min-depth 4 test_qc_raw.vcf.gz genome1.fna.fai --use-conda --cores 8

The workflow still works when run using Snakemake:

# from root of this repo
snakemake -s snparcher/workflow/modules/qc/Snakefile -d test/run_with_snakemake --use-conda --cores 8

CLI Usage

snparcher

snparcher!

Usage:

$ snparcher [OPTIONS] COMMAND [ARGS]...

Options:

  • --install-completion: Install completion for the current shell.
  • --show-completion: Show completion for the current shell, to copy it or customize the installation.
  • --help: Show this message and exit.

Commands:

  • qc

snparcher qc

Usage:

$ snparcher qc [OPTIONS] VCF FAI

Arguments:

  • VCF: Path to vcf file [required]
  • FAI: Path to fai file [required]

Options:

  • --coords-file PATH: File containing coordinates for samples in VCF. [required]
  • --min-depth INTEGER: Min depth of SNPs to keep [required]
  • --exclude-chrs TEXT: Comma seperated list of chromosomes to exclude.
  • --nclusters INTEGER: Number of clusters for PCA [default: 3]
  • --google-api-key TEXT: Google API key for satellite map
  • --help: Show this message and exit.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snparcher-0.1.0.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snparcher-0.1.0-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

Details for the file snparcher-0.1.0.tar.gz.

File metadata

  • Download URL: snparcher-0.1.0.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for snparcher-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9752beddabbd8af69d357175f38e8b5459e946e940023fa51d68a16ff5cca61f
MD5 e6cb9e31510668ff006353ebfc32ae15
BLAKE2b-256 a5da3b62b9d3c554be4010444cc203e98d29b8715610f94aa495307b6419c169

See more details on using hashes here.

Provenance

The following attestation bundles were made for snparcher-0.1.0.tar.gz:

Publisher: release.yaml on cademirch/snparcher-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snparcher-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: snparcher-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 35.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for snparcher-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d6890c4493866087300f159e7fd72d48851b2ac033e64fc73875d45f5290e36
MD5 16f479b41aa55906aa309aab450af643
BLAKE2b-256 9071d4ff8ccab706c5add76d3eca1cd3838d3a400eb0f9564334922cb86f702e

See more details on using hashes here.

Provenance

The following attestation bundles were made for snparcher-0.1.0-py3-none-any.whl:

Publisher: release.yaml on cademirch/snparcher-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page