Skip to content

Instantly share code, notes, and snippets.

@GavinHuttley
GavinHuttley / piqtree_example.py
Created February 5, 2026 23:38
How to calculate a pairwise distance matrix using an empirical protein substitution model with piqtree.
# code from this piqtree issue https://github.com/iqtree/piqtree/issues/392
import cogent3 as c3
aln = c3.get_dataset("brca1")
# piqtree requires 3 sequences for a tree fit, so select an outgroup
outgroup = "Wombat"
# You need to write a loop that iterates all name pairs aside from the outgroup, use `for ingroups in itertools.combinations([n for n in aln.names if n != outgroup], 2):...`
# then in the loop
ingroups = ["Human", "Mouse"]
@GavinHuttley
GavinHuttley / cogent3_example.py
Created February 4, 2026 01:28
Takes nexus partition and alignment files and writes out separate alignment, dropping sequences with 0 canonical bases.
import os
from pathlib import Path
import tarfile
import cogent3
from cogent3.core.alignment import Alignment
COMPRESSED_DATA = Path("turtle_dataset.tar.gz")
TURTLE_PATH = Path("turtle_dataset/turtle.nex")
PARTITION_PATH = Path("turtle_dataset/partition.nex")