alterlab-gtars

$npx mdskill add AlterLab-IEU/AlterLab-Academic-Skills/alterlab-gtars

Runs high-performance genomic interval analysis with gtars Rust toolkit.

  • Computes overlaps, Jaccard, coverage between BED region sets.
  • Depends on Python gtars package and optional Rust CLI binary.
  • Selects gtars operations based on task: overlap, index, tokenize, or digest.
  • Returns results as Python objects or files via Read/Write tools.

SKILL.md

.github/skills/alterlab-gtarsView on GitHub ↗
---
name: alterlab-gtars
description: Runs high-performance genomic interval analysis with gtars (databio), a Rust toolkit with Python bindings — the performance-critical backend for the geniml ML library. Use when computing overlaps/jaccard/coverage between BED region sets, indexing intervals with IGD, generating uniwig accumulation/coverage tracks, tokenizing genomic regions for ML, splitting single-cell fragments into pseudobulks, or computing GA4GH refget sequence digests. NOT for training region embeddings (use alterlab-geniml) or non-genomic spatial joins (use alterlab-geopandas). Part of the AlterLab Academic Skills suite.
license: MIT
allowed-tools: Read, Write, Edit, Bash
compatibility: No API key required. Python API runs locally via `uv run python` with the `gtars` package (PyPI, v0.8). The CLI is a separate Rust binary (`gtars-cli`, install via cargo).
metadata:
    skill-author: AlterLab
    version: "1.1.0"
---

# Gtars: Genomic Tools and Algorithms in Rust

## Overview

Gtars (from databio, the lab behind `geniml`) is a high-performance Rust toolkit for manipulating, analyzing, and processing genomic interval data. Its primary purpose is to be the performance-critical backend for `geniml`, a Python library for machine learning on genomic intervals. It provides overlap/set operations, IGD overlap indexing, coverage (uniwig) tracks, region tokenization for ML, single-cell fragment pseudobulking, and GA4GH refget sequence-collection management.

Use this skill when working with:
- Genomic interval files (BED) — overlaps, jaccard, set ops, coverage
- IGD indexing for fast overlap queries over large interval databases
- Coverage / accumulation tracks via uniwig
- Genomic ML preprocessing and region tokenization
- Single-cell fragment files (split into pseudobulks by cluster)
- Reference sequence digests and retrieval (refget)

> Version note: examples are verified against the **`gtars` Python package v0.8** (PyPI). The Python API is exposed through submodules — `gtars.models`, `gtars.tokenizers`, `gtars.refget`, `gtars.utils` — NOT as flat top-level functions. There is no `gtars.igd` or `gtars.uniwig` Python submodule; IGD building and uniwig track generation are CLI-only.

## Installation

### Python package

```bash
uv pip install gtars   # or: uv add gtars
```

Import surface (verified, v0.8):

```python
from gtars.models import RegionSet, Region, RegionSetList
from gtars.tokenizers import Tokenizer, tokenize_fragment_file
from gtars import refget          # RefgetStore, digest_fasta, sha512t24u_digest, ...
from gtars import utils           # read/write .gtok token files
```

### CLI (separate Rust binary)

The CLI ships as the `gtars-cli` crate (binary name `gtars`) and is installed with Cargo. Most subcommands are behind feature flags:

```bash
# All commonly used commands
cargo install gtars-cli --features "uniwig overlaprs igd bbcache scoring fragsplit genomicdist"

# Or a subset
cargo install gtars-cli --features "uniwig igd"
```

Available CLI subcommands: `igd`, `overlaprs`, `uniwig`, `bbcache`, `pb` (fragment pseudobulking), `scoring`, `genomicdist`, `ranges`, `consensus`, `prep`. Flag sets differ per subcommand and evolve across versions — always confirm with `gtars <command> --help`.

## Core Capabilities

Gtars is organized into specialized modules, each focused on specific genomic analysis tasks:

### 1. Overlap Detection and Set Operations

Detect overlaps and compute set operations / similarity between region sets with `RegionSet` (Python), or index a large interval database with IGD (CLI).

**When to use:**
- Finding overlapping regulatory elements, comparing ChIP-seq peaks
- Variant annotation; identifying shared genomic features
- Jaccard / overlap-coefficient similarity between BED files

**Quick example (Python):**
```python
from gtars.models import RegionSet

peaks = RegionSet("chip_peaks.bed")
promoters = RegionSet("promoters.bed")

# Regions in peaks that overlap a promoter (the real method is subset_by_overlaps)
in_promoters = peaks.subset_by_overlaps(promoters)
in_promoters.to_bed("peaks_in_promoters.bed")

print(peaks.count_overlaps(promoters))  # per-region overlap counts
print(peaks.jaccard(promoters))         # similarity score
```

For querying a large reference database many times, build an IGD index once via the CLI (`gtars igd create ...`) and search it (`gtars igd search ...`). See `references/overlap.md`.

### 2. Coverage / Accumulation Tracks (uniwig, CLI)

Generate coverage / accumulation tracks from a BED or BAM file with the uniwig CLI subcommand.

**When to use:**
- ATAC-seq accessibility profiles, ChIP-seq coverage, RNA-seq read coverage

**Quick example (CLI):**
```bash
# uniwig reads a sorted BED/BAM and writes accumulation tracks.
# Flags differ by version; confirm with `gtars uniwig --help`.
gtars uniwig --file fragments.bed --filetype bed \
             --fileheader coverage --outputtype bw
```

See `references/coverage.md` for verified flags and `RegionSet.coverage()` for an in-memory alternative.

### 3. Genomic Tokenization

Convert genomic regions into discrete tokens for ML (the preprocessing layer `geniml` builds on).

**When to use:**
- Preprocessing peaks/regions into a fixed vocabulary for genomic ML models
- Feeding token IDs to geniml or custom transformer models

**Quick example (Python):**
```python
from gtars.tokenizers import Tokenizer
from gtars.models import Region

tokenizer = Tokenizer.from_bed("universe.bed")   # vocab = the universe BED
tokens = tokenizer.tokenize([Region("chr1", 1000, 2000, None)])  # -> ['chr1:1000-2000']
ids = tokenizer.convert_tokens_to_ids(tokens)                     # -> [<int>]
```

See `references/tokenizers.md`. Note: the class is `Tokenizer` (there is no `TreeTokenizer`).

### 4. Reference Sequence Management (refget)

Compute GA4GH refget digests and manage/retrieve reference sequences.

**When to use:**
- Validating reference genome integrity via sequence digests
- Building a local sequence-collection store and extracting subsequences

**Quick example (Python):**
```python
from gtars import refget

# Digest a FASTA into a GA4GH SequenceCollection (no sequence data loaded)
collection = refget.digest_fasta("hg38.fa")

# Or a one-off sequence digest
d = refget.sha512t24u_digest("ACGTACGT")   # 'GS_...'-style truncated SHA-512/24
```

See `references/refget.md` for `RefgetStore` (load, store, and `get_substring`).

### 5. Fragment Pseudobulking (pb, CLI)

Split a single-cell fragment file into pseudobulks based on a cluster/cell-group mapping.

**When to use:**
- Processing single-cell ATAC-seq; cluster-based fragment aggregation

**Quick example (CLI):**
```bash
# The fragsplit feature exposes the `pb` (pseudobulk) subcommand.
gtars pb --fragments fragments.bed.gz --mapping cluster_mapping.tsv
```

The Python side also offers `gtars.tokenizers.tokenize_fragment_file(...)` for tokenizing fragments directly. See `references/cli.md`.

### 6. Fragment / Region Scoring

Score region/fragment files against reference datasets with the `scoring` CLI subcommand.

**When to use:**
- Evaluating enrichment of regions against a reference universe
- Batch quality-metric computation across samples

```bash
gtars scoring --help   # confirm subcommands and flags for your installed version
```

## Common Workflows

### Workflow 1: Peak Overlap Analysis

Identify peaks overlapping promoters (Python):

```python
from gtars.models import RegionSet

peaks = RegionSet("chip_peaks.bed")
promoters = RegionSet("promoters.bed")

overlapping_peaks = peaks.subset_by_overlaps(promoters)
overlapping_peaks.to_bed("peaks_in_promoters.bed")

# Iterate results (regions expose .chr/.start/.end)
for r in overlapping_peaks:
    print(r.chr, r.start, r.end)
```

### Workflow 2: IGD index + repeated overlap queries (CLI)

Index a large reference database once, then search it many times:

```bash
# Build the IGD database from a directory or list of BED files
gtars igd create --help     # confirm the exact input/output flags for your version

# Search the database with query regions
gtars igd search --help
```

### Workflow 3: ML Preprocessing (tokenization)

Prepare genomic regions for an ML model:

```python
from gtars.tokenizers import Tokenizer
from gtars.models import RegionSet

# Step 1: Build a tokenizer from the universe BED (defines the vocabulary)
tokenizer = Tokenizer.from_bed("universe.bed")

# Step 2: Tokenize a region set (tokenize accepts a RegionSet or a list of Region)
regions = RegionSet("training_peaks.bed")
tokens = tokenizer.tokenize(regions)                      # list of 'chr:start-end' strings
ids = tokenizer.convert_tokens_to_ids(tokens)             # integer IDs for the model

# Step 3: feed `ids` to geniml or a custom model (see alterlab-geniml for training)
```

## Python vs CLI Usage

**Use Python API when:**
- Integrating with analysis pipelines
- Need programmatic control
- Working with NumPy/Pandas
- Building custom workflows

**Use CLI when:**
- Quick one-off analyses
- Shell scripting
- Batch processing files
- Prototyping workflows

## Reference Documentation

- **`references/python-api.md`** — `RegionSet` / `Region` operations, set ops, overlaps, export
- **`references/overlap.md`** — overlap detection and IGD indexing
- **`references/coverage.md`** — uniwig coverage tracks
- **`references/tokenizers.md`** — region tokenization for ML
- **`references/refget.md`** — refget digests and `RefgetStore`
- **`references/cli.md`** — CLI subcommand overview

## Relationship to geniml

gtars is the Rust performance backend for `geniml` (databio's ML-on-genomic-intervals library). Use gtars for the heavy interval ops and tokenization; use `geniml` (skill `alterlab-geniml`) for embedding/model training built on top of those tokens.

## Data Formats

- **BED**: genomic intervals (3-column or extended) — the core input
- **BigWig / WIG**: coverage / accumulation tracks (uniwig output)
- **FASTA**: reference sequences (refget)
- **Fragment files**: single-cell fragments (often `.bed.gz`), with a separate cluster-mapping file for `pb`

## Verifying the API

This package's surface differs between releases and the Python and CLI APIs are NOT mirror images. Before relying on an unfamiliar method or flag, confirm against the installed version:

```bash
uv run python -c "from gtars import models, tokenizers, refget; print(dir(models), dir(tokenizers), dir(refget))"
gtars <command> --help
```

More from AlterLab-IEU/AlterLab-Academic-Skills

SkillDescription
alterlab-abm-mesaBuilds agent-based models of social systems with Mesa 3 — the current AgentSet API (model.agents.shuffle_do('step'), auto-assigned unique_id, mandatory super().__init__(seed=...)), cell spaces (mesa.discrete_space OrthogonalMooreGrid / classic mesa.space grids), the DataCollector, batch_run parameter sweeps, and SolaraViz — for emergence, segregation, diffusion, opinion dynamics, and cooperation models. It uses the Mesa 3.x API (the old mesa.time schedulers like RandomActivation are removed) and treats the model as a generative theory to be validated, not just run. Use when the request mentions an agent-based model, Mesa, simulating interacting agents, or emergent macro behavior from micro rules. For discrete-event (queueing/process) simulation prefer alterlab-simpy; for reinforcement learning prefer alterlab-stable-baselines3. Part of the AlterLab Academic Skills suite.
alterlab-academic-careerPrepares academic career documents and professional-development materials for faculty and researchers. Use when drafting academic CVs, research statements, teaching philosophies, diversity statements, faculty-position cover letters, tenure dossiers, promotion narratives, academic portfolios, or mentorship statements, and when planning conference-networking strategy, building academic web presence, setting up ORCID profiles, or understanding impact metrics. Part of the AlterLab Academic Skills suite.
alterlab-accreditation-aolScaffolds program-level Assurance-of-Learning (AoL) documentation for AACSB (2020 Standard 5) and ABET (Criterion 3 Student Outcomes, Criterion 4 Continuous Improvement) accreditation — program learning outcomes / competency goals, curriculum-to-outcome mapping matrices, direct- and indirect-assessment plans, rubric design, and closing-the-loop continuous-improvement narratives — and validates the structure of an outcome-mapping matrix with scripts/aol_matrix.py. Use when the user needs AACSB or ABET assurance-of-learning material, a program-learning-outcomes set, a curriculum/outcome map or coverage matrix, a direct/indirect assessment plan, a closing-the-loop report, or accreditation self-study text. For single-course design or course rubrics prefer alterlab-teaching-design; for post-award grant reports prefer alterlab-grant-reporting. Part of the AlterLab Academic Skills suite.
alterlab-adaptyvSubmits and tracks protein-testing experiments on the Adaptyv Bio Foundry cloud lab (wet-lab validation), and optimizes protein sequences before submission with computational tools (NetSolP, SoluProt, SolubleMPNN, ESM). Use when designing proteins that need wet-lab validation - binding/affinity screening, expression testing, thermostability, or fluorescence assays - or when submitting experiments to the Foundry API, browsing the target catalog, tracking experiment status, retrieving results, or pre-screening sequences for solubility/expression. Triggers on "Adaptyv", "Foundry API", "cloud lab", "biolayer interferometry / BLI", "wet-lab validation". Part of the AlterLab Academic Skills suite.
alterlab-aeonRuns time series machine learning with the aeon library — classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search via scikit-learn compatible APIs. Use when working with temporal data, sequential patterns, or time-indexed observations (univariate or multivariate) that need specialized algorithms beyond standard ML approaches. Part of the AlterLab Academic Skills suite.
alterlab-akademik-tesvikComputes the annual Turkish academic-incentive (akademik teşvik) score for Devlet (state) university öğretim elemanı (academic staff) from a classified activity list, applying the verified Akademik Teşvik Ödeneği Yönetmeliği (2018/11834) Faaliyet Hesaplama Tablosu headline puanları (Proje 20, Araştırma 15, Yayın 30, Patent 30, Atıf 30, Tebliğ 20, Ödül 20) with the k (author-count), p (Q1 1/Q2 0.8/Q3 0.5/Q4 0.25), and r (project-role) coefficients via türü puanı = Σ(faaliyet oranları) × headline (MADDE 8/2), then enforcing the per-type headline ceilings, the 100 cap (MADDE 8/3), and the net-30 payment gate (MADDE 10/3) in a deterministic scripts/tesvik_score.py. Use when the user wants to calculate akademik teşvik puanı, check the en az 30 (net-30) threshold, apply TABLO 4 ceilings, or estimate teşvik eligibility; keeps its coefficients separate from doçentlik scoring. For doçentlik point eligibility prefer alterlab-docentlik-eligibility. Part of the AlterLab Academic Skills suite.
alterlab-alpha-vantageAccesses real-time and historical stock market data, forex rates, cryptocurrency prices, commodities, economic indicators, and 50+ technical indicators via the Alpha Vantage API (requires a free API key from alphavantage.co). Use when fetching stock prices (OHLCV), company fundamentals (income statement, balance sheet, cash flow), earnings, options data, market news/sentiment, insider transactions, GDP, CPI, treasury yields, gold/silver/oil prices, Bitcoin/crypto prices, forex exchange rates, or calculating technical indicators (SMA, EMA, MACD, RSI, Bollinger Bands). Part of the AlterLab Academic Skills suite.
alterlab-alphafoldPredict protein 3D structures with AlphaFold2 via ColabFold — MMseqs2-accelerated MSAs, monomer and AlphaFold2-Multimer complex folding, and confidence-based validation (pLDDT, pTM/ipTM, PAE). Use when folding a protein sequence or complex from FASTA, generating a predicted structure with confidence metrics, ranking models, or checking self-consistency of a design. For co-folding a protein WITH a small-molecule ligand or predicting binding affinity prefer alterlab-boltz; for antibody–antigen or one-FASTA multi-entity complexes prefer alterlab-chai; to LOOK UP an already-computed structure prefer alterlab-alphafold-db; for ESM embeddings or inverse folding prefer alterlab-esm. Part of the AlterLab Academic Skills suite.
alterlab-alphafold-dbAccess the AlphaFold DB of 200M+ AI-PREDICTED protein structures — retrieve models by UniProt accession, download PDB/mmCIF files, and analyze prediction confidence metrics (pLDDT, PAE). Use when a UniProt ID needs a computationally predicted 3D structure or when no experimental structure exists, for homology modeling, protein engineering, or structure-based drug discovery; for EXPERIMENTALLY determined structures (X-ray, cryo-EM, NMR) prefer alterlab-pdb, and for protein sequences, annotations, or accession ID mapping prefer alterlab-uniprot instead. Part of the AlterLab Academic Skills suite.
alterlab-anndataBuild, slice, concatenate, read, and write AnnData annotated data matrices (obs, var, X, layers, obsm, uns) — the scverse data STRUCTURE, not an analysis pipeline. Use when creating or wrangling .h5ad/zarr files, managing cell and gene annotations, concatenating batches, or handling layers/obsm/backed-mode; for the QC, normalization, clustering, UMAP, and differential-expression analysis pipeline prefer alterlab-scanpy instead, and for RNA velocity from spliced/unspliced layers prefer alterlab-scvelo instead. Part of the AlterLab Academic Skills suite.