/genome-annotation:protein-phylogenyfrom genome-annotation
Generates a .qmd analysis script for protein phylogeny inference: alignment (MAFFT), optional trimming, and tree building (IQ-TREE). Use when building gene/protein trees from amino acid sequences.
Ships in genome-annotation. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Pipeline for building protein phylogenies across deep evolutionary distances. Designed for single domains, whole single-domain proteins, and multi-domain proteins, from ~10 to several thousand sequences, spanning sponges to all eukaryotes.
If the user says "gene tree" they may mean protein sequences. Confirm if ambiguous, or inspect the input sequences (amino acid alphabet vs nucleotide).
This skill generates a reproducible .qmd analysis script (Python) rather than running commands directly. The workflow is:
.qmd script encoding all decisions as configuration
variables, following quarto-docs and script-organization skill conventionsquarto render, producing analysis
outputs in a fresh outs/<subdirectory>/XX_script_name/<run_name>/ directoryOne script per major deliverable (one protein family or domain tree). All pipeline steps
go in one .qmd unless there is a strong reason to split.
Resolve unsettled scientific choices with the user before generating the script. Reuse applicable decisions in the project's registered record, reminding the user which inputs and methods they cover; do not reopen unchanged choices. Use the recommendation logic below when a choice is new or materially changes the interpretation.
Validate the FASTA file before proceeding. The generated script includes a validation chunk (see Phase 2) that runs these checks automatically, but also inspect the file during the discussion phase to inform algorithm/model recommendations.
* appears mid-sequence (not just at the end), warn the user| Condition | Algorithm | MAFFT flags |
|---|---|---|
| Single domain or whole protein, <= 2000 seq | L-INS-i (default) | --localpair --maxiterate 1000 --reorder |
| Multi-domain protein with variable linkers | E-INS-i | --genafpair --maxiterate 1000 --reorder |
| > 2000 sequences | auto (MAFFT decides) | --auto --reorder |
Recommendation: "You have N sequences, median length X aa. This looks like a [single-domain / multi-domain / whole-protein] dataset. I'd recommend MAFFT [L-INS-i / E-INS-i / auto]. Does that sound right?"
Do not trim unless the user requests it. For deep divergences, aggressive trimming can remove phylogenetically informative sites. Good models (site-heterogeneous) handle noisy columns.
| Tool | Mode | Best for |
|---|---|---|
| ClipKIT | kpic-gappy | General purpose |
| BMGE | BLOSUM30 | Very deep divergences with compositional heterogeneity |
| Tier | Model | When to use | Approximate time (166 seq) |
|---|---|---|---|
| 1 | MFP (ModelFinder) | Quick exploration, screening | ~15-30 min |
| 1.5 | Q.pfam+F+R6 | Fast gene trees, batch screening — skip model search | ~10-20 min |
| 2 | ELM+C60+G PMSF (default) | Deep eukaryotic phylogenies | ~3-8 hours |
| 2 alt | LG+C60+F+R PMSF | Non-eukaryotic or for comparison | ~3-8 hours |
| 3 | PhyloBayes CAT+GTR | Maximum rigor, < 200 seq | Hours to days |
-B 1000 -alrt 1000-b 1000) for publication-quality final treesThe user inspects the tree after inference and decides if anything looks wrong. Do not use TreeShrink or similar tools automatically.
Once all decisions are resolved, generate a .qmd script following these conventions.
Follow the script-organization skill:
scripts/<subdirectory>/XX_name.qmd (next available number)outs/<subdirectory>/XX_name/<run_name>/ (fresh per run)Generate a Python .qmd with these sections in order:
Configuration chunk — all decisions as named variables at the top:
#| label: config
# ---- Pipeline Configuration ----
# Resolved during discussion; change here to re-run with different options.
# IQ-TREE uses RANDOM_SEED from the setup chunk; record it with the command and tool logs.
RUN_NAME = "run_01" # Choose a new name for each execution; never reuse retained output
INPUT_FASTA = PROJECT_ROOT / "data/phylogenetics/sequences.fasta"
MIN_LENGTH_FRACTION = 0.5 # Remove sequences shorter than this fraction of median
RUN_CDHIT = False # Redundancy reduction
CDHIT_THRESHOLD = 0.99
MAFFT_ALGORITHM = "linsi" # "linsi" | "einsi" | "auto"
MAFFT_THREADS = 8 # Parallel threads for MAFFT alignment
RUN_TRIMMING = False
TRIMMING_TOOL = "clipkit" # "clipkit" | "bmge"
IQTREE_TIER = 2 # 1 = MFP, 1.5 = Q.pfam+F+R6, 2 = ELM+C60+G PMSF, 3 = PhyloBayes
IQTREE_MATRIX = "ELM" # "ELM" | "LG" (Tier 2 only)
IQTREE_THREADS = 8 # Fixed thread count (AUTO crashes with PMSF in v3.0.1)
BOOTSTRAP_REPS = 1000
Fresh-run setup — run after configuration and before filtering, alignment or any other
analysis write. The standard setup's out_dir is the parent for this script's runs. Choose a
new RUN_NAME for changed inputs/settings or a retry; an existing run is preserved even when
it is incomplete. Inspect and explicitly retire a disposable failed run separately if needed.
Open the retained report to inspect a completed run; rerendering the analysis creates a new run.
Do not skip a step just because its output exists. This template does not implement automatic
resume; a separately reviewed resume must establish matching inputs, settings and completion.
#| label: prepare-run
run_dir = out_dir / RUN_NAME
run_dir.mkdir(parents=True, exist_ok=False)
out_dir = run_dir
print(f"Fresh analysis output directory: {out_dir}")
Record the actual input identity/hash, resolved configuration, seed, environment/tool versions and producing source commit in the project's run record. Preserve the rendered report too when it is retained or shared; choose a fresh report destination rather than overwriting it.
FASTA validation chunk — runs before any analysis:
#| label: validate-input
from Bio import SeqIO
from collections import Counter
VALID_AA = set("ACDEFGHIKLMNPQRSTVWY")
EXTENDED_AA = set("XUBZJO*")
fasta_path = INPUT_FASTA
assert fasta_path.exists(), f"FASTA file not found: {fasta_path}"
records = list(SeqIO.parse(fasta_path, "fasta"))
assert len(records) > 0, "FASTA file is empty or not valid FASTA format"
# Basic stats
lengths = [len(r.seq) for r in records]
median_len = sorted(lengths)[len(lengths) // 2]
print(f"Sequences: {len(records)}")
print(f"Length: median {median_len}, min {min(lengths)}, max {max(lengths)}")
# Duplicate IDs
ids = [r.id for r in records]
dupes = [id for id, count in Counter(ids).items() if count > 1]
if dupes:
print(f"WARNING: {len(dupes)} duplicate IDs — MAFFT keeps only last: {dupes[:5]}")
# Empty sequences
empty = [r.id for r in records if len(r.seq) == 0]
if empty:
print(f"WARNING: {len(empty)} empty sequences: {empty[:5]}")
# Alphabet check — nucleotide vs protein
all_chars = Counter()
for r in records:
all_chars.update(str(r.seq).upper())
total_chars = sum(all_chars.values())
nuc_chars = sum(all_chars.get(c, 0) for c in "ATGCN")
if total_chars > 0 and nuc_chars / total_chars > 0.9:
print(f"WARNING: {nuc_chars/total_chars:.0%} nucleotide chars — may not be protein")
# Non-standard characters
nonstandard = {c: n for c, n in all_chars.items()
if c not in VALID_AA and c not in EXTENDED_AA and c != "-"}
if nonstandard:
print(f"WARNING: Non-standard characters: {nonstandard}")
# Stop codons mid-sequence
for r in records:
seq = str(r.seq)
if "*" in seq[:-1]: # ignore terminal stop
print(f"WARNING: Internal stop codon (*) in {r.id}")
# Short sequence filter
short_cutoff = median_len * MIN_LENGTH_FRACTION
short = [r.id for r in records if len(r.seq) < short_cutoff]
if short:
print(f"\n{len(short)} sequences < {short_cutoff:.0f} aa "
f"({MIN_LENGTH_FRACTION:.0%} of median)")
records = [r for r in records if len(r.seq) >= short_cutoff]
print(f"Retained {len(records)} sequences after length filter")
filtered_fasta = out_dir / "input_filtered.fasta"
SeqIO.write(records, filtered_fasta, "fasta")
else:
print(f"\nAll sequences >= {short_cutoff:.0f} aa — no filtering needed")
filtered_fasta = fasta_path
Alignment output — execute in the fresh run directory:
aligned_fasta = out_dir / "aligned.fasta"
print("Running MAFFT alignment...")
# ... subprocess call; fail on nonzero exit before using the alignment ...
print(f" Alignment: {n_seqs} sequences x {n_cols} columns")
Subprocess pattern — consistent error handling:
result = subprocess.run(
cmd, capture_output=True, text=True
)
if result.returncode != 0:
print(f"STDERR: {result.stderr[:500]}")
raise RuntimeError("MAFFT failed")
MAFFT_FLAGS = {
"linsi": ["--localpair", "--maxiterate", "1000", "--reorder", "--thread", str(MAFFT_THREADS)],
"einsi": ["--genafpair", "--maxiterate", "1000", "--reorder", "--thread", str(MAFFT_THREADS)],
"auto": ["--auto", "--reorder", "--thread", str(MAFFT_THREADS)],
}
MAFFT's interleaved output format is incompatible with IQ-TREE — if the alignment was produced with interleaved output, convert to standard (sequential) FASTA with BioPython before handing it to IQ-TREE.
Tier 1 — Quick baseline:
cmd = [
"iqtree3", "-s", str(input_aln),
"-m", "MFP",
"-seed", str(RANDOM_SEED),
"-B", str(BOOTSTRAP_REPS), "-alrt", str(BOOTSTRAP_REPS),
"-nstop", "50", "-T", "AUTO",
"-pre", str(out_dir / "tree")
]
Tier 1.5 — Fast fixed model (batch screening, no model search):
cmd = [
"iqtree3", "-s", str(input_aln),
"-m", "Q.pfam+F+R6",
"-seed", str(RANDOM_SEED),
"-B", str(BOOTSTRAP_REPS), "-alrt", str(BOOTSTRAP_REPS),
"-nstop", "50", "-T", "AUTO",
"-pre", str(out_dir / "tree")
]
Tier 2 — Two-pass PMSF (default for deep eukaryotic phylogenies):
model = f"{IQTREE_MATRIX}+C60+G" if IQTREE_MATRIX == "ELM" else f"{IQTREE_MATRIX}+C60+F+R"
# Pass 1: guide tree
guide_tree = out_dir / "guide.treefile"
cmd_pass1 = [
"iqtree3", "-s", str(input_aln),
"-m", model,
"-seed", str(RANDOM_SEED),
"-nstop", "50", "-T", str(IQTREE_THREADS),
"-pre", str(out_dir / "guide")
]
subprocess.run(cmd_pass1, check=True)
# Pass 2: PMSF tree with bootstrap
final_tree = out_dir / "pmsf.treefile"
cmd_pass2 = [
"iqtree3", "-s", str(input_aln),
"-m", model,
"-seed", str(RANDOM_SEED),
"-ft", str(guide_tree),
"-B", str(BOOTSTRAP_REPS), "-alrt", str(BOOTSTRAP_REPS),
"-nstop", "50", "-T", str(IQTREE_THREADS),
"-pre", str(out_dir / "pmsf")
]
subprocess.run(cmd_pass2, check=True)
Bug workaround (IQ-TREE 3.0.1):
-T AUTOcrashes with an assertion error during PMSF site frequency computation (computePartialParsimonyFast). Use a fixed thread count (e.g.,-T 8) instead. Re-test with future IQ-TREE releases.
Tier 3 — PhyloBayes (special case):
PhyloBayes runs for hours to days and does not fit the "render once" model. The .qmd
should launch chains and note that convergence must be checked separately:
print("PhyloBayes requires long-running chains.")
print("Launch manually:")
print(f" pb_mpi -d {input_phy} -cat -gtr -x 1 10000 chain1")
print(f" pb_mpi -d {input_phy} -cat -gtr -x 1 10000 chain2")
print("Check convergence with bpcomp -x 2500 chain1 chain2")
Parse IQ-TREE output and report:
# Read support values from treefile
import re
tree_text = (out_dir / "pmsf.treefile").read_text()
supports = re.findall(r'\)([\d.]+)/([\d.]+):', tree_text)
ufboot = [float(s[1]) for s in supports]
shalrt = [float(s[0]) for s in supports]
total = len(ufboot)
print(f"=== Tree Inference Summary ===")
print(f"Sequences: {n_seqs}")
print(f"Alignment: {n_cols} columns")
print(f"Model: {model} (Tier {IQTREE_TIER})")
print(f"UFBoot >= 95: {sum(1 for v in ufboot if v >= 95)}/{total}")
print(f"UFBoot >= 70: {sum(1 for v in ufboot if v >= 70)}/{total}")
print(f"SH-aLRT >= 80: {sum(1 for v in shalrt if v >= 80)}/{total}")
print(f"\nTree file: {final_tree}")
print(f"\nNext: use tree-formatting skill for visualization")
The rendered script produces these files in outs/<subdirectory>/XX_name/<run_name>/:
| File | Description |
|---|---|
pmsf.treefile | ML tree with UFBoot/SH-aLRT support (Tier 2) |
pmsf.contree | Bootstrap consensus tree |
pmsf.iqtree | Full IQ-TREE report |
pmsf.sitefreq | PMSF site frequency profiles |
guide.treefile | Pass 1 guide tree (Tier 2) |
aligned.fasta | MAFFT alignment |
BUILD_INFO.txt | Optional stage record for independent or expensive inference; otherwise use the workflow record |
# Activate the project's declared environment in this same shell.
# On a cluster, use its supported module/Conda setup and an appropriate allocation.
quarto render scripts/SUBDIRECTORY/XX_name.qmd --execute-dir "$PWD" --output-dir "$PWD/outs/SUBDIRECTORY/XX_name/reports/run_01/"
Run from repository root after activating the declared environment; replace SUBDIRECTORY and the script name. Follow
quarto-docs for a declared Quarto project or cluster runtime. Match the report's run_01 to
RUN_NAME and use a fresh report destination for each render. Analysis outputs remain in the
separate <run_name>/ directory, so report creation cannot occupy the fresh analysis destination.
For long-running Tier 2 analyses, consider rendering in a screen/tmux session.
These are not part of the standard pipeline but can be added as additional chunks:
-m GTR+R
on the recoded alignment.-zb 10000 -au.| Tool | Purpose | Install |
|---|---|---|
| MAFFT | Alignment | conda install -c bioconda mafft |
| IQ-TREE 3 | Tree inference | conda install -c bioconda iqtree (ensure v3+) |
| BioPython | FASTA I/O, sequence handling | pip install biopython |
| CD-HIT | Redundancy reduction (optional) | conda install -c bioconda cd-hit |
| ClipKIT | Trimming (optional) | pip install clipkit |
| BMGE | Trimming (optional) | conda install -c bioconda bmge |
| PhyloBayes-MPI | Bayesian inference (optional) | conda install -c bioconda phylobayes-mpi |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub musserlab/lab-claude-skills --plugin genome-annotation5 skills in this plugin
/buscoRun BUSCO completeness assessment on genomes, transcriptomes, or predicted proteomes. Generates conda env setup, shared-lineage download, SLURM array scripts with sample-sheet-driven (input × lineage) fan-out, a local single-input fallback, and an aggregator. Use when running BUSCO, assessing genome/transcriptome/proteome completeness, scoring against an odb10 lineage, or when the user mentions "BUSCO", "BUSCO score", "completeness", "C/S/D/F/M", "ortholog completeness", "genome/transcriptome/assembly QC", or asks whether an assembly is complete. Sanitizes FASTA headers automatically — BUSCO 6.x rejects "/" in headers, which trips up IsoSeq3 transcripts. Do NOT load for FCS-GX foreign-sequence screening (use fcs-gx), eggNOG-mapper functional annotation (use eggnog-mapper), or PROST structural homology (use prost-annotation)./gene-lookupLook up gene or protein information from biological database IDs and accessions. Use when working with gene IDs, protein accessions, or identifiers from UniProt, Ensembl, FlyBase, WormBase, NCBI/RefSeq, or similar databases. Covers: identifying what database an ID comes from, converting IDs to gene symbols or names, retrieving protein function or annotation, batch querying APIs, and cross-referencing between databases. Use whenever someone asks "what gene is this", "look up this protein", "get info on these accessions", or needs to map between identifier systems. Also use for phylogenetic tree tip label gene name resolution.
Other plugins' skills for the same job