Skip to main content

sherlock-tools

Python library behind the nf-core/sherlock pipeline, which looks for shared genetic signals between two traits and narrows them down to tissue, cell type, gene and SNP.

The pipeline's bin/ scripts import it, but it also works on its own in Python.

What it does

QualityControl cleans and harmonises one set of GWAS summary statistics (built on polars):

  • fixes data types, strips chr, keeps autosomes (1-22) by default
  • stops with an error if any P-value is outside 0-1 (e.g. a -log10 P column)
  • removes missing values and duplicated SNP IDs
  • removes indels, palindromic, multi-allelic and non-autosomal variants (each can be switched off: drop_indels, drop_palindromes, drop_multiallelic, drop_non_autosomal, all default True)
  • MAF and (optional) INFO filters (INFO is only applied when both info_col and info_thresh are given)
  • liftover between GRCh37 and GRCh38 (UCSC chain file)
  • optional removal of the MHC (drop_mhc, default True) and APOE (drop_apoe, default False) regions
  • aligns betas to the risk allele
  • writes one sample size column N (effective N for case/control traits)

Output columns follow LDSC naming: SNP CHR BP A1 A2 BETA SE P N [FRQ] [INFO]. A1 is the risk allele: where BETA was negative, A1/A2 are swapped and BETA flipped (FRQ becomes 1 - FRQ), so BETA is always positive.

Sample size is used as given and never rescaled. If your file has a half-size effective N column (e.g. PGC NEFFDIV2 / NEFF_HALF), double it first, or leave n_col empty and give n_cases + n_controls. n_col must be a per-SNP sample size, not a count of studies.

Install

pip install sherlock-tools

Requires Python >= 3.12.

Example

import polars as pl
from sherlock_tools.preprocessing import QualityControl

sumstats = pl.read_csv("AD.tsv", separator="\t")

qc = QualityControl(
    sumstats=sumstats,
    snp_col="SNP", chr_col="CHR", pos_col="BP",
    a1_col="A1", a2_col="A2",
    beta_col="BETA", se_col="SE", pval_col="P",
    n_col="N",
    maf_thresh=0.01,
    freq_col="FRQ",
    genome_build="GRCh37",
    target_genome_build="GRCh38",
    chain_file="hg19ToHg38.over.chain",
    trait_type="cc",
)

clean = qc.run()

# rows removed / left after each step
print(pl.DataFrame(qc.summary, schema=["step", "removed", "remaining"], orient="row"))

Development install

pip install -e "sherlock-tools[dev]"
pytest sherlock-tools/tests

Changes

  • 0.1.3: INFO filter is skipped when no threshold is set (previously removed every row); new P-value range check; per-step counts in qc.summary; indel / palindrome / multiallelic / non-autosomal filters can be switched off.
  • 0.1.2: package metadata and README.
  • 0.1.1: error when builds differ and no chain file is given.

Licence

MIT

Metadata

Release files for sherlock-tools 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sherlock-tools 0.1.3
File Size Uploaded Provenance Actions
sherlock_tools-0.1.3.tar.gz 8.9 kB Without provenance Details for sherlock_tools-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sherlock-tools 0.1.3
File Interpreter ABI Platform Actions
sherlock_tools-0.1.3-py3-none-any.whl Python 3 none any Details for sherlock_tools-0.1.3-py3-none-any.whl

Total release size: 16.3 kB

Release files / sherlock_tools-0.1.3.tar.gz

Download URL sherlock_tools-0.1.3.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6c8803087935c7ace912edb88a2caffe5c263d7180cb8889f39dabbf7f810524
BLAKE2b-256 checksum
How to use checksums
97506e8e1ea23d0f6a53337c470548f73c1e8e1d4d20ab64abd0fe60330f088e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / sherlock_tools-0.1.3-py3-none-any.whl

Download URL sherlock_tools-0.1.3-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee4342ca33e6ae0a01d2b1164c0e8bddc62186144104d2e2f735c56043d9cfcf
BLAKE2b-256 checksum
How to use checksums
32204810a52ddb0ddbd943d5782f8551148dd156ed815591a048ba1618f03ad0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for sherlock-tools 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page