Metadata-Version: 2.4
Name: omicsweave
Version: 0.2.0
Requires-Dist: numpy>=1.26.0
Summary: A unified framework for loading multi-omics data into model training
Requires-Python: >=3.12
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://github.com/CladeTeam/OmicsWeave/tree/main/docs
Project-URL: Issues, https://github.com/CladeTeam/OmicsWeave/issues
Project-URL: Repository, https://github.com/CladeTeam/OmicsWeave

<div align="center">

<img src="https://raw.githubusercontent.com/CladeTeam/OmicsWeave/main/assets/logo.svg" alt="OmicsWeave logo" width="160">

# OmicsWeave

**From genomic files to model inputs — one region query away.**

[![Python](https://img.shields.io/badge/python-3.12%2B-blue.svg)](https://pypi.org/project/omicsweave/)
[![PyPI](https://img.shields.io/pypi/v/omicsweave)](https://pypi.org/project/omicsweave/)
[![Platform](https://img.shields.io/badge/platform-linux%20x86__64%20%7C%20aarch64-lightgrey.svg)](#installation)
[![Backend](https://img.shields.io/badge/backend-Rust-orange.svg)](https://github.com/CladeTeam/OmicsWeave/tree/main/crates)

[Quick start](#quick-start) · [Support matrix](#support-matrix) · [Documentation](#documentation) · [Examples](https://github.com/CladeTeam/OmicsWeave/tree/main/examples)

</div>

---

OmicsWeave is a unified Python toolkit for turning multi-omics files into training data. Ask for a genomic region and get back NumPy arrays — sequence, signal, intervals, multi-species alignments, reads, variants, personal sequences or contact maps — straight from the indexed file, without unpacking the whole dataset first. A native Rust engine does the decoding, and the same engine converts formats, quantifies alignments and scans motifs, so data preparation, exploration and data loading all run on one set of tools.

## Highlights

- 🧬 **One query, every layer.** Sequence, signal, peaks, multiple alignments, reads, variants and Hi-C are read by the same genomic keys — regions, transcripts from GTF / GFF3, 2-D windows — straight into NumPy.
- ⚡ **Built for training.** Rust decoding outside the GIL, readers that drop into PyTorch DataLoader workers, and direct writes into batch buffers.
- 🧪 **Personal genomes and variant effects.** Apply a BCF per haplotype for personal sequences, or one variant at a time for effect prediction.
- 🔎 **Composable motif scanning.** MEME, JASPAR, HOCOMOCO and other motif formats in one file; FIMO, MAST, MCAST and GLAM2Scan as building blocks over a single pass.
- 🔁 **Convert and quantify.** `ow convert` makes text formats queryable; `ow quant` turns one pass over a BAM into coverage, count matrices, methylation, contacts and more.
- 🎯 **Matches the reference tools.** Same results as htslib, libBigWig, `bcftools consensus` and MEME Suite; files written are standard.

## Quick start

```sh
pip install omicsweave
```

```python
from omicsweave.query import SequenceReader, TrackReader, ContactReader
from omicsweave.types import Region, ContactWindow

region = Region("chr1", 1_000_000, 1_131_072)

with SequenceReader("genome.fa.gz") as genome, TrackReader("atac.bw") as atac:
    bases = genome.fetch(region).bases                    # uint8 [131072], ASCII
    signal = atac.signal(region).values                   # float32 [131072], NaN = no data
    binned = atac.bins(region, 128, ("mean", "max"))      # float32 [2, 1024]

with ContactReader("contacts.hic") as hic:
    tile = hic.matrix(ContactWindow(region, region, 2048)).values  # float32 [64, 64]
```

Transcripts come straight from the annotation:

```python
from omicsweave.annotation import Annotation

annotation = Annotation.read("genes.gtf.gz", attributes=None)
mrna_key = annotation.locus("ENST00000269305")           # a Spliced key, strand included

with SequenceReader("genome.fa.gz") as genome:
    mrna = genome.fetch(mrna_key).text                   # spliced, 5' → 3'
```

Personal sequences come from a BCF over the reference, either a genome's view or one variant's view:

```python
from omicsweave.query import ConsensusReader
from omicsweave.types import Haplotype, Record, Variant

with SequenceReader("genome.fa.gz") as genome, ConsensusReader("cohort.bcf", genome) as cohort:
    window = Region("chr17", 43_040_904, 43_049_096)
    hap1, hap2 = cohort.fetch_batch(window, [Haplotype("NA12878", "1"), Haplotype("NA12878", "2")])

    alt = cohort.fetch(window, Record(0))                # only the window's first variant applied
    snv = cohort.fetch(window, Variant(43_045_000, "C", "T"))  # one variant, chosen by content
```

Motifs are converted once into FFM, then scanned in memory:

```python
from omicsweave import motif
from omicsweave.query import MotifReader

with MotifReader("jaspar.ffm") as motifs:
    program = motif.compile(motifs, motif.Background.uniform(motifs.alphabet))

with SequenceReader("genome.fa.gz") as genome:
    promoters = [genome.fetch(Region("chr1", s - 1_000, s)) for s in (1_000_000, 2_000_000)]
hits, counts = program.scan(promoters, motif.Hits(pvalue=1e-4), motif.Counts(pvalue=1e-4))
# hits: sequence / motif / start / end / strand / score / pvalue columns
# counts: sparse sequence × motif matrix (CSR), .to_dense() or .to_scipy()
```

Files that are not indexed yet are converted once, and BAMs are quantified in one pass:

```sh
ow convert peaks.bed peaks.bb --chrom-sizes genome.fa.fai
ow convert cohort.vcf.gz cohort.bcf --index
ow convert contacts.mcool contacts.hic -t 8 -m 4G
ow convert multiz100way.maf.gz multiz100way.bigmaf --ref-species hg38
ow convert JASPAR2026_CORE_vertebrates_pfms.jaspar jaspar.ffm
ow convert cisbp/pwms/*.txt cisbp.ffm

ow quant cells.bam -o results --gtf genes.gtf --genes single-cell --velocity --matrix mtx
```

## Support matrix

➜ convert first · — not applicable · other entries in **Read by region** describe how the format is read. Text inputs may be plain, gzip or BGZF compressed.

| Data | Format | Read by region | Convert from it | Convert into it | Write from Python | Index | In `ow quant` |
|---|---|:---:|---|---|---|---|---|
| **Sequence** | [FASTA](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/fasta.md) | bases | bgzip FASTA, 2bit | — | `FastaWriter` | `.fai` | reference |
| | [bgzip FASTA](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/fasta.md) | bases | bgzip FASTA, 2bit | from FASTA | `FastaWriter` | `.fai` + `.gzi` | reference |
| | [gzip FASTA](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/fasta.md) | ➜ | bgzip FASTA, 2bit | — | — | — | — |
| | [2bit](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/2bit.md) | bases, soft mask | — | from FASTA | `TwoBitWriter` | built in | reference |
| **Signal** | [bigWig](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/bigwig.md) | per base, bins, runs | — | from bedGraph, wig, bedMethyl | `BigWigWriter` | built in | output: coverage, methylation |
| | [bedGraph](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/bedgraph.md) | ➜ | bigWig, bigBed | — | — | — | — |
| | [wig](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/wig.md) | ➜ | bigWig | — | — | — | — |
| **Intervals** | [bigBed](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/bigbed.md) | overlapping records | — | from BED, bedGraph, bedMethyl | `BigBedWriter` | built in | peaks as features |
| | [BED](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/bed.md) | ➜ | bigBed | — | — | — | — |
| | [bedMethyl](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/bedmethyl.md) | ➜ | bigBed (all columns), bigWig (one column) | — | — | — | — |
| **Multiple alignments** | [bigMaf](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/bigmaf.md) | species × reference-base matrices | — | from MAF | — | built in | — |
| | [MAF](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/maf.md) | ➜ | bigMaf | — | — | — | — |
| **Alignments** | [BAM](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/bam.md) | records, chosen fields | coordinate-sorted BAM | from SAM, CRAM, BAM | — | `.bai` / `.csi` | **input** |
| | [CRAM 3.0 / 3.1](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/cram.md) | records, chosen fields | BAM | — | — | `.crai` | ➜ BAM |
| | [SAM](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/sam.md) | ➜ | BAM | — | — | — | ➜ BAM |
| **Variants** | [BCF](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/bcf.md) | genotypes, INFO / FORMAT, filters, consensus | — | from VCF | — | `.csi` | known sites, allele sites |
| | [VCF](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/vcf.md) | ➜ | BCF | — | — | — | ➜ BCF |
| **Contacts** | [.hic v8 / v9](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/hic.md) | dense tiles, pixels | — | from cool, mcool, pairs, Juicer short, HiC-Pro | `HicWriter`, `HicBuilder` | built in | output |
| | [cool](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/cool.md) / [mcool](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/mcool.md) | ➜ | .hic | — | — | — | — |
| | [4DN pairs](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/pairs.md) | ➜ | .hic | — | — | — | output |
| | [Juicer short](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/juicer-short.md) | ➜ | .hic | — | — | — | — |
| | [HiC-Pro valid pairs](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/hicpro-pairs.md) | ➜ | .hic | — | — | — | — |
| **Annotation** | [GTF](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/gtf.md) / [GFF3](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/gff3.md) | loaded in memory | — | — | `write_gtf`, `write_bed12` | not needed | genes, promoters, gene activity, ... |
| **Motifs** | [FFM](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/ffm.md) | motifs by ID or index | FFM | from the motif text formats below, one or many files | `FfmWriter` | built in | — |
| | [Motif texts](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/motif-texts.md): MEME / STREME, JASPAR (`.jaspar`, raw `.pfm`), TRANSFAC, HOMER, CIS-BP, HOCOMOCO (PCM / PWM / DPCM / DPWM), Cluster-Buster, BaMM, ProBound, GLAM2 | ➜ | FFM | — | — | — | — |
| **Loader metadata** | [Sidecar](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/sidecar.md) | — | — | — | `sidecar=True` on writers | — | — |

See the [format overview](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/README.md) for coordinates, compression and indexes across formats.

### Query results at a glance

| Reader | Input | Returns |
|---|---|---|
| `SequenceReader` | FASTA, bgzip FASTA, 2bit | `uint8` bases (reverse complement on `-`) |
| `TrackReader` / `StrandedTrackReader` | bigWig (one, or a plus / minus pair) | `float32` per-base signal; mean / min / max / sum / std / coverage bins; stored runs |
| `IntervalReader` | bigBed | `uint32` starts / ends + the remaining BED fields; typed columns by autoSql |
| `MsaReader` | bigMaf | `uint8` alignment `[species, length]` in reference coordinates |
| `AlignmentReader` | BAM, CRAM | fixed columns as arrays; names, sequences, qualities, CIGARs, tags and `MM` / `ML` base modifications on request |
| `VariantReader` | BCF | `int8` genotype tensor; typed INFO / FORMAT arrays; bcftools `-i` / `-e` filters |
| `ConsensusReader` | BCF + reference | personal sequences per sample, haplotype or ALT (a genome's view), or with one variant applied (a variant's view); batched; optional chain |
| `ContactReader` | .hic | `float32` contact tiles or nonzero pixels, raw counts, BP or FRAG bins |
| `MotifReader` | FFM | motif models by ID or index, ready to compile for scanning |

### Motif matching

| Capability | What you get |
|---|---|
| Motif collections | MEME / STREME, JASPAR, TRANSFAC, HOMER, CIS-BP, HOCOMOCO, Cluster-Buster, BaMM, ProBound and GLAM2 merged into one FFM file |
| Site scanning | windows past a p-value or score threshold, dense score tracks, each sequence's best window |
| Sequence features | sparse sequence × motif count matrices, ready for model inputs |
| Sequence ranking | MAST combined p- and E-values with non-overlapping hit tiling |
| Motif clusters | MCAST cis-regulatory module search with p-, E- and q-values |
| Gapped profiles | GLAM2Scan alignments of gapped motifs |
| MEME Suite parity | `fimo`, `mast`, `mcast` and `glam2scan` match MEME Suite 5.5.9 output |

Every reduction is collected in one pass over the sequences, any Markov-order background can be given, and each statistic (best-of-n, combined p-values, E- / q-values) can be swapped for your own. See the [motif guide](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/motif.md).

### Quantification products

| Assay | Product | Output |
|---|---|---|
| Any | `Coverage` | bigWig, combined or per strand, optional CPM scaling |
| scRNA / bulk RNA | `Counts.rna_single_cell` / `rna_bulk` | gene × cell / sample matrices, featureCounts-style table |
| RNA velocity | `Counts(..., velocity=True)` | `spliced` / `unspliced` / `ambiguous` layers |
| Splicing | `Junctions` | STAR-style junction table, optional matrix |
| Metabolic labeling | `Labeling`, `Labeled` | conversion histograms, mismatch profiles, `labeled` layer |
| scATAC | `Atac` | fragments + index, barcode metrics, peak / tile / gene-activity matrices |
| ChIP-seq / CUT&Tag | `Counts.chip` | peak or bin counts |
| DNA methylation | `Methylation` | per-cytosine table, beta / coverage bigWig, M-bias, region matrices |
| Hi-C / Micro-C | `Contacts` | 4DN pairs, raw-count .hic, per-cell metrics |
| Allele counting | `Alleles`, `AlleleGenes` | `ref` / `alt` / `other` layers, haplotype-resolved gene counts |

Matrices are written as CellPack (`.cpk`, default), Matrix Market or CSV. OmicsWeave starts from aligned reads: it does not align, call peaks, call variants or correct barcodes.

## Installation

OmicsWeave is on PyPI and supports Python 3.12 or newer; prebuilt wheels target Linux on x86_64 and aarch64.

```sh
pip install omicsweave
# or, in a uv-managed project
uv add omicsweave
```

This installs the `omicsweave` package and the `ow` command. NumPy is the only runtime dependency; `pyarrow` is optional for Arrow string export.

## Documentation

| Guide | What it covers |
|---|---|
| [Query by region](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/query.md) | keys, readers, result shapes, strands, caching, concurrency, DataLoader use |
| [Convert formats](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/convert.md) | supported routes, indexes, sorting, resource budgets, dry runs |
| [Quantify alignments](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/quant.md) | products, counting rules, matrix storage, assay-specific options |
| [Match motifs](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/motif.md) | FFM collections, scoring, scans, reductions and gapped profiles |
| [Format guides](https://github.com/CladeTeam/OmicsWeave/blob/main/docs/formats/README.md) | every format: what it stores, how it is laid out, how OmicsWeave supports it |
| [Examples](https://github.com/CladeTeam/OmicsWeave/tree/main/examples) | PyTorch data loaders for sequence-to-function and multi-modal models |

The guides are written in Chinese.

