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 coordinate-sorted BAM or CRAM files. 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

Write one deduplicated, indexed BAM for all selected genes:

nanofetch tumor.bam --panel cns --combined cns.bam --index

Read a custom panel containing whitespace- or comma-separated symbols and # comments:

nanofetch tumor.bam --gene-file my-panel.txt --combined panel.bam --index

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

Indexed CRAM input is supported. Supply its reference explicitly when required:

nanofetch tumor.cram EGFR --reference GRCh38.fa --index

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

Export resolved padded regions as BED without extracting BAMs:

nanofetch tumor.bam --gene-file my-panel.txt --write-bed regions.bed --dry-run

Write compact gene-body coverage QC for every selected gene:

nanofetch tumor.bam --panel cns --combined cns.bam --summary coverage.tsv

The summary reports alignment count, mean depth, mean mapping quality, and the percentage of gene bases covered at 1×, 10×, and 30×.

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 default 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 coordinate-sorted and indexed: BAM uses BAI or CSI, while CRAM uses CRAI. CRAM decoding can use --reference FASTA. 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 writes one BAM per gene by default or a single union with --combined. Potential later additions include custom GTF annotations, CRAM output, mate retrieval, and all-segment retrieval.

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.3.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.3.0-py3-none-any.whl (4.2 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nanofetch-0.3.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.3.0.tar.gz
Algorithm Hash digest
SHA256 23c36ec658af688f044d522909d4a2e8bce28b549a11091e3c026cd4d1910274
MD5 c869c753cb3afb1a420c55a0b6b1ffaa
BLAKE2b-256 11f2c636cfc3b15f84ceca90db6f05c5549276bd5e6d5a6aa308e8c1e702a9e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanofetch-0.3.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.3.0-py3-none-any.whl.

File metadata

  • Download URL: nanofetch-0.3.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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50c9fdbe8b5ae86056203c892d3befa1036498e5920a106fe969de8ec52512a4
MD5 74b27d24ed5612ff6fba4ac1d3f40480
BLAKE2b-256 ba5d0fe0c37e955d7950fe3bf0506bd52f308f38e26930e9464a64ee31b9e86a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanofetch-0.3.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

This release

0.3.0 This release

2 files

0.2.0

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