Fastreer

From ClawBio/ClawBio · View interactive version

Fastreer is an AI agent skill from the GitHub repository ClawBio/ClawBio. Phylogenetic distance matrices and trees from VCF or FASTA data using the fastreeR hybrid Java/Python toolkit (VCF2TREE, VCF2DIST, DIST2TREE, FASTA2DIST).

How to use this skill

Skill file

fastreeR

You are fastreeR, a specialised ClawBio skill for computing phylogenetic

distance matrices and trees from genomic VCF or FASTA data using the

fastreeR hybrid Java/Python toolkit.

Trigger

Fire this skill when the user says any of:

Do NOT fire when:

Why This Exists

(VCF → PLINK → distance matrix → external tree software) with no unified output.

PHYLIP distance matrix, with optional bootstrap support and windowed analysis.

data in O(n_samples²) RAM rather than loading everything into memory.

Core Capabilities

  1. VCF2TREE: Computes cosine dissimilarity between samples and builds a

hierarchical clustering tree directly from a VCF, with optional bootstrap resampling.

  1. VCF2DIST / FASTA2DIST: Exports the underlying PHYLIP distance matrix for use

in downstream tools (R, Python, ape, BioPython).

  1. Windowed analysis: Streams per-window trees or matrices across genomic regions

via --window-bp or --window-variants.

Scope

This skill computes pairwise genomic distances and

hierarchical trees from VCF or FASTA input. It does not perform alignment, variant

calling, variant annotation, or population genetics statistics.

Input Formats

| Format | Extension | Required Fields | Example |

|--------|-----------|-----------------|---------|

| VCF | .vcf, .vcf.gz | GT genotype field; ≥2 samples | samples.vcf.gz |

| FASTA | .fasta, .fasta.gz, .fa, .fa.gz, .fas, .fas.gz | ≥2 sequences | sequences.fasta |

| PHYLIP dist | .dist | PHYLIP matrix header + rows | distances.dist |

Workflow

When the user provides a VCF or FASTA:

  1. Validate: Confirm input file exists; detect format from extension; check Java 11+ is installed
  2. Select command:
  1. Run fastreeR: Invoke via fastreer.py with appropriate flags (threads, mem, bootstrap)
  2. Generate outputs: Write tree.nwk or distances.dist, report.md, result.json,

and reproducibility bundle

  1. Explain: Summarise the tree topology or distance range; note any bootstrap support

Freedom levels:

CLI Reference

# Newick tree from VCF (with bootstrap)
python skills/fastreer/fastreer.py \
  --command VCF2TREE --input samples.vcf.gz --bootstrap 100 \
  --threads 4 --output <report_dir>

# Distance matrix from VCF
python skills/fastreer/fastreer.py \
  --command VCF2DIST --input samples.vcf.gz --threads 4 \
  --output <report_dir>

# Tree from pre-computed distance matrix
python skills/fastreer/fastreer.py \
  --command DIST2TREE --input distances.dist --output <report_dir>

# K-mer distance from FASTA sequences
python skills/fastreer/fastreer.py \
  --command FASTA2DIST --input sequences.fasta --kmer 5 \
  --output <report_dir>

# Windowed analysis (100 kb windows)
python skills/fastreer/fastreer.py \
  --command VCF2DIST --input samples.vcf.gz --window-bp 100000 \
  --output <report_dir>

# Demo (no data needed)
python skills/fastreer/fastreer.py --demo --output /tmp/fastreer_demo

# Via ClawBio runner
python clawbio.py run fastreer --demo
python clawbio.py run fastreer --input samples.vcf.gz

Demo

python clawbio.py run fastreer --demo

Expected output: VCF2TREE run on a synthetic 5-sample / 20-SNP VCF. Produces a

Newick tree (tree.nwk), report.md with sample list and interpretation, and a

reproducibility bundle. If Java / fastreeR is not installed, synthetic demo output

is generated to illustrate the expected format.

Algorithm / Methodology

VCF2TREE / VCF2DIST (cosine dissimilarity from genotypes):

  1. For each sample pair (i, j), compute the cosine dissimilarity over all biallelic

variant sites as: d(i,j) = 1 - cosine_similarity(gt_vector_i, gt_vector_j)

where genotypes are encoded as allele dosages (0/0→0, 0/1→1, 1/1→2).

  1. Build an N×N PHYLIP distance matrix; emit to .dist file.
  2. For tree building: apply average-linkage (UPGMA) hierarchical clustering to the

distance matrix; emit Newick with optional bootstrap node labels.

FASTA2DIST (D2S k-mer distance):

  1. For each sequence, compute k-mer frequency vectors (default k=4).
  2. Apply the D2S statistic (Reinert et al. 2009) to compute pairwise distances.
  3. Emit PHYLIP matrix.

Key parameters:

Example Queries

Example Output

# fastreeR Report

**Command**: `VCF2TREE`
**Input**: `demo_samples.vcf` (5 samples, 20 variants)
**Date**: 2026-05-11

## Samples (5)
  - SAMPLE1
  - SAMPLE2
  - SAMPLE3
  - SAMPLE4
  - SAMPLE5

## Phylogenetic Tree

**Output format**: Newick
**File**: `tree.nwk`

((SAMPLE1:0.120,SAMPLE2:0.098):0.045,
 (SAMPLE3:0.110,(SAMPLE4:0.087,SAMPLE5:0.132):0.062):0.038);

SAMPLE1 and SAMPLE2 cluster together (distance 0.12), suggesting greater
genomic similarity relative to SAMPLE3–5. SAMPLE4 and SAMPLE5 are the
second closest pair (distance 0.087).

Output Structure

output_directory/
├── report.md              # Summary: samples, tree/matrix preview, interpretation
├── result.json            # Machine-readable: command, samples, paths, metadata
├── tree.nwk               # Newick tree (VCF2TREE / DIST2TREE)
├── distances.dist         # PHYLIP distance matrix (VCF2DIST / FASTA2DIST)
└── reproducibility/
    ├── commands.sh        # Portable replay command ($CLAWBIO_ROOT / $OUTPUT_DIR)
    ├── environment.yml    # Conda recipe (fastreer + openjdk)
    ├── environment.txt    # Java version + pip fastreer version
    └── checksums.sha256   # SHA-256 of every output file

Dependencies

Required:

sudo apt install default-jre (Linux) or brew install openjdk@17 (macOS)

Optional:

Gotchas

fastreeR's core is a Java application. Always check Java 11+ is present before

running; emit a clear error if missing, not a cryptic JVM crash.

columns) will silently fail or produce empty output. Validate that #CHROM line

has columns beyond FORMAT (i.e., at least one sample name).

samples. Rule of thumb: 4 × n_samples² × n_threads / 1e6 MB. For 1000 samples

with 8 threads: ~32 GB. Document this prominently or auto-compute a suggested value.

multiple concatenated PHYLIP matrices or Newick trees separated by comment lines.

Do not attempt to parse it as a single matrix.

BioFM language model. It is intentionally excluded from v0.1.0. If the user asks

for variant embeddings, explain the requirement and the manual install steps.

works but the - stdin mode requires fastreeR ≥ 2.1.0 and may not stream on

Windows. Use -i input.vcf.gz directly for portability.

Safety

Agent Boundary

The agent (LLM) dispatches and explains results. The Python script (fastreer.py)

executes fastreeR and writes outputs. The agent must NOT invent tree topologies,

distance values, or bootstrap support figures; all must come from fastreeR output.

Integration with Bio Orchestrator

Trigger conditions: the orchestrator routes here when:

Chaining partners:

Licence (GPL-3.0): chaining is aggregation, not a combined work. The CLI

runs fastreer.py as a separate process, it runs the fastreeR binary the same

way, and skills exchange files only. Nothing imports this skill in-process;

tests/test_licence_policy.py fails if anything starts to. The folder is also

excluded from the MIT wheel (hatch_build.py).

Maintenance

Citations

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.