# Phylogenetics

Build and analyze phylogenetic trees using MAFFT (multiple alignment), IQ-TREE 2...

- Repository: https://github.com/LeonChaoX/qinyan-academic-skills (996 stars)
- Category: Data and ML
- License: Unknown
- Last updated: 2026-07-20
- Runs scripts: yes, review before use

## Install

Claude Code: `npx skills add LeonChaoX/qinyan-academic-skills --skill phylogenetics -g -a claude-code -y`
Codex: `npx skills add LeonChaoX/qinyan-academic-skills --skill phylogenetics -g -a codex -y`
Cursor: `npx skills add LeonChaoX/qinyan-academic-skills --skill phylogenetics -g -a cursor -y`
Gemini CLI: `npx skills add LeonChaoX/qinyan-academic-skills --skill phylogenetics -g -a gemini-cli -y`

## Description

Build and analyze phylogenetic trees using MAFFT (multiple alignment), IQ-TREE 2 (maximum likelihood), and FastTree (fast NJ/ML). Visualize with ETE3 or FigTree. For evolutionary analysis, microbial genomics, viral phylodynamics, protein family analysis, and molecular clock studies.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Phylogenetics

## Overview

Phylogenetic analysis reconstructs the evolutionary history of biological sequences (genes, proteins, genomes) by inferring the branching pattern of descent. This skill covers the standard pipeline:

1. **MAFFT**, Multiple sequence alignment
2. **IQ-TREE 2**, Maximum likelihood tree inference with model selection
3. **FastTree**, Fast approximate maximum likelihood (for large datasets)
4. **ETE3**, Python library for tree manipulation and visualization

**Installation:**
```bash
# Conda (recommended for CLI tools)
conda install -c bioconda mafft iqtree fasttree
pip install ete3
```

## When to Use This Skill

Use phylogenetics when:

- **Evolutionary relationships**: Which organism/gene is most closely related to my sequence?
- **Viral phylodynamics**: Trace outbreak spread and estimate transmission dates
- **Protein family analysis**: Infer evolutionary relationships within a gene family
- **Horizontal gene transfer detection**: Identify genes with discordant species/gene trees
- **Ancestral sequence reconstruction**: Infer ancestral protein sequences
- **Molecular clock analysis**: Estimate divergence dates using temporal sampling
- **GWAS companion**: Place variants in evolutionary context (e.g., SARS-CoV-2 variants)
- **Microbiology**: Species phylogeny from 16S rRNA or core genome phylogeny

## Standard Workflow

### 1. Multiple Sequence Alignment with MAFFT

```python
import subprocess
import os

def run_mafft(input_fasta: str, output_fasta: str, method: str = "auto",
               n_threads: int = 4) -> str:
    """
    Align sequences with MAFFT.

    Args:
        input_fasta: Path to unaligned FASTA file
        output_fasta: Path for aligned output
        method: 'auto' (auto-select), 'einsi' (accurate), 'linsi' (accurate, slow),
                'fftnsi' (medium), 'fftns' (fast), 'retree2' (fast)
        n_threads: Number of CPU threads

The rest: https://github.com/LeonChaoX/qinyan-academic-skills/blob/HEAD/skills/05-生物信息与基因组学/phylogenetics/SKILL.md
