Skip to main content

NanoFetch

Ridiculously easy gene-region BAM extraction.

nanofetch tumor.bam EGFR --index
Genome: GRCh38
Annotation: GENCODE 50 (GRCh38.p14)
Wrote EGFR.bam (18432 alignments) + EGFR.bam.bai

nanofetch turns gene symbols into reproducible genomic intervals, adds padding, and extracts overlapping alignments from a coordinate-sorted BAM. It supports GRCh37, GRCh38, and the telomere-to-telomere T2T-CHM13v2.0 (hs1) assembly.

Install

Python 3.9 or newer is required.

python -m pip install nanofetch

For an isolated command-line installation, use pipx install nanofetch.

For local development:

git clone https://github.com/AlexanderM-M/Nanofetch.git
cd Nanofetch
python -m pip install -e '.[test]'
pytest

pysam is the only runtime dependency. A separate samtools installation is not required.

Usage

One gene, using the default 1 Mb padding on both sides:

nanofetch tumor.bam EGFR

Several genes:

nanofetch tumor.bam --genes EGFR CDK4 PDGFRA CDKN2A MET

Compact families are accepted:

nanofetch tumor.bam CDKN2A/B NTRK1/2/3

Use the built-in CNS convenience panel:

nanofetch tumor.bam --panel cns --index --output-dir cns-regions

Use T2T-CHM13 explicitly, or let nanofetch detect it from chromosome lengths:

nanofetch t2t-aligned.bam EGFR --genome t2t
nanofetch t2t-aligned.bam --panel cns --genome hs1

Inspect the resolved regions without writing BAMs:

nanofetch tumor.bam EGFR --dry-run
Genome: GRCh38
Annotation: GENCODE 50 (GRCh38.p14)
EGFR   chr7:54018820-56211628   EGFR.bam

Generate a reproducibility manifest:

nanofetch tumor.bam EGFR MET --index --manifest regions.tsv

SVG coverage plot

Create a self-contained coverage overview for one extracted gene:

nanofetch tumor.bam EGFR --plot EGFR.coverage.svg

The plot shows mean aligned-base depth in fixed-width bins, the annotated gene body, requested extraction span, assembly and annotation provenance, and counts for primary, supplementary, and secondary alignments. It visualizes the output BAM, so --include-supplementary and --include-secondary are reflected in the plot. SVG generation has no dependency beyond NanoFetch itself.

Example NanoFetch coverage plot

Run nanofetch --help for all options.

What is selected?

An alignment is selected when its aligned reference span overlaps the padded gene interval. It does not need to span the entire region.

By default, secondary (0x100) and supplementary (0x800) records are excluded. Use --include-secondary and --include-supplementary to retain records of those types that overlap the region.

--include-supplementary does not retrieve distant segments merely because a different segment from the same read overlaps the requested gene. That operation requires a read-name-based second pass and is intentionally outside the v0.1 semantics.

Overlapping padded intervals for multiple copies of the same symbol are merged, so an alignment is not written twice. Separate gene output BAMs may contain the same alignment when their padded regions overlap; this is expected.

Genome detection and contig names

Automatic detection compares exact primary-chromosome lengths in the BAM header. It will stop rather than guess when the build is ambiguous. The explicit spellings below are accepted:

Assembly Accepted names Bundled annotation
GRCh37 grch37, hg19 GENCODE 50lift37
GRCh38 grch38, hg38 GENCODE 50
T2T-CHM13v2.0 t2t, hs1, chm13, chm13v2.0 RefSeq/Liftoff v5.3

Both chr7 and 7 naming styles are supported. T2T GenBank names such as CP068271.2 and RefSeq names such as NC_060931.1 are also mapped to their chromosomes.

Input and output safety

The input must be a coordinate-sorted BAM with a BAI or CSI index. nanofetch does not modify the input or create an input index automatically.

Existing output BAMs are protected unless --force is supplied. Outputs are written to a temporary file and moved into place only after writing succeeds. When an output is replaced, any stale BAI or CSI is removed. --index creates a fresh BAI. Plot and manifest files receive the same collision protection, and manifests are also written atomically.

Before extraction starts, nanofetch checks all planned BAM, index, plot, and manifest paths for conflicts. It refuses to use the input BAM or either of its conventional index paths as an output, even when --force is supplied.

Built-in CNS panel

The cns panel currently contains:

EGFR PDGFRA CDK4 MDM2 MDM4 MET CDKN2A CDKN2B NF1 PTEN TERT
BRAF FGFR3 NTRK1 NTRK2 NTRK3 ALK

This is a transparent convenience set, not a validated clinical assay. Use nanofetch --list-panels to inspect installed panels.

Annotation provenance

The package works offline. It bundles compact gene-level tables generated from pinned upstream files; it does not bundle complete GTF/GFF files.

Source URLs, SHA-256 digests, labels, and record counts are stored in src/nanofetch/data/annotations.json. The deterministic build script is scripts/build_annotations.py.

Scope

NanoFetch currently writes one BAM per gene. Potential later additions include custom BED/GTF annotations, CRAM output, mate retrieval, all-segment retrieval, and combined multi-gene BAMs.

License

MIT. T2T consortium data are released under CC0; see the upstream CHM13 repository.

Download files

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

Source Distribution

nanofetch-0.2.0.tar.gz (4.2 MB view details)

Uploaded Source

Built Distribution

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

nanofetch-0.2.0-py3-none-any.whl (4.2 MB view details)

Uploaded Python 3

File details

Details for the file nanofetch-0.2.0.tar.gz.

File metadata

  • Download URL: nanofetch-0.2.0.tar.gz
  • Upload date:
  • Size: 4.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for nanofetch-0.2.0.tar.gz
Algorithm Hash digest
SHA256 72e4efe15b54572de171b921f9952bbcb6a13af4c089b6d2e5641e92ae51ea5c
MD5 a199bb2795ec44b3676d04a455df9696
BLAKE2b-256 3e78668fdbb43741214c2c7f221f54fdb1a2d46b277072985f2d66c1f6b5f21f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanofetch-0.2.0.tar.gz:

Publisher: publish.yml on AlexanderM-M/Nanofetch

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

File details

Details for the file nanofetch-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: nanofetch-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for nanofetch-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3274ee39efd33a761510c9d554f34a26de6a40c8af72acff15d564c7bb622890
MD5 9a50816ad48b712900c96c3207950fe2
BLAKE2b-256 b21b90f05520299515040625f7ed6cdba130f5bf15ff09dd9d2f7ba712a31d3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanofetch-0.2.0-py3-none-any.whl:

Publisher: publish.yml on AlexanderM-M/Nanofetch

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

Release history Release notifications | RSS feed

0.3.0

2 files

This release

0.2.0 This release

2 files

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