Types, file formats and exports for protist community analyses built on PR2 or SILVA: ranked lineages, evidence rolled up a taxonomy, jplace placements, and iTOL-ready trees.
A protist amplicon analysis produces a table of lineage strings with counts, often a set of phylogenetic placements, and eventually a figure. Protoctist covers that stretch in Julia:
-
reads the tables your classifier wrote (CSV, TSV, ECSV) and the placements your placer wrote (jplace);
-
parses lineages against the rank ladder they were assigned under — PR2 v5 (9 ranks) or SILVA (7 ranks) — and refuses to mix the two;
-
builds the taxonomy those lineages span and rolls counts and evidence status up it in one linear pass, without dropping a read;
-
writes annotated Newick and the iTOL dataset files for the result;
-
records the conditions a run was judged under and decides whether two runs may be pooled, giving every reason when they may not.
using Protoctist
run = load_protist_run("merged.csv") # ProtistRun(3 rows, 14 taxa, ladder=:pr2)
clade_cumulus(run)[1:3] # cumulative reads per clade, largest first
# "root" => 57, "Eukaryota" => 57, "Excavata" => 40
export_iqtree_annotated(run, "out/")
# out/tree.newick out/itol_counts.txt out/itol_status.txt out/itol_contamination.txtUpload tree.newick to iTOL and drop the three dataset
files onto it. The dataset files are keyed by taxon name, so they also apply to
an IQ-TREE or EPA-ng tree whose labels use the same names.
using Pkg
Pkg.add(url = "https://github.com/hyperpolymath/Protoctist.jl")Julia 1.9 or later. Protoctist has no package dependencies; adding it to an existing environment cannot change the version of anything already there.
p = TaxPath("Eukaryota;TSAR;Alveolata;Ciliophora") # PR2 ladder by default
at_rank(p, :subdivision) # "Ciliophora"
at_rank(p, :genus) # nothing — the lineage does not reach genus
s = TaxPath("Bacteria;Proteobacteria;"; ladder = :silva)
at_rank(s, :phylum) # "Proteobacteria"
s == TaxPath("Bacteria;Proteobacteria"; ladder = :pr2) # false: different laddersA TaxPath carries its ladder, and paths on different ladders are never equal.
An interior blank (a;;c) is an unfilled rank: the lineage continues, and the
next label is placed at its own rank rather than shifted up. A trailing ; is
not a rank at all, so SILVA- and QIIME 2-style strings parse as written.
load_protist_run rolls up counts. To carry evidence, give rollup_counts
rows with a status and, where classification left candidates open, a
residual:
tree = build_taxonomy_tree(["Eukaryota;TSAR;Rhizaria;Cercozoa",
"Eukaryota;TSAR;Alveolata"])
rows = [
(path = TaxPath("Eukaryota;TSAR;Rhizaria;Cercozoa"), count = 10, status = FACTIVE),
(path = TaxPath("Eukaryota;TSAR;Alveolata;Dinoflagellata"), count = 3,
status = BELIEF, residual = LineageResidual(2, false, false)),
]
annot = rollup_counts(tree, rows)
annotate_newick(tree, annot)
# ... Alveolata[&&NHX:rank=division:count=3:cum=3:f=0:b=3:res=3:novel=0:contam=0] ...FACTIVE marks an assignment the evidence entails; BELIEF one it supports
without entailing. LineageResidual records how many named candidates remained,
whether a novel taxon is admissible, and whether contamination is suspected.
The second row names Dinoflagellata, which the tree does not contain. It is
counted at Alveolata, the deepest ancestor the tree does contain, and appears
there as a non-zero own count on an interior node — coarser, but present and
visible.
b = Protoctist.Formats.read_jplace("epa_result.jplace")
b.placements # every candidate edge for every query
Protoctist.Formats.best_placements(b) # one per query, highest like_weight_ratio
Protoctist.Formats.write_jplace(b, "filtered.jplace")Every candidate edge is kept, including those for multiplicity names (nm).
Selection is by like_weight_ratio, never by the order the placer listed them
in. A null field is read as NaN and written back as null.
a = build_manifest((reference = "PR2", version = "5.0.0", ladder = :pr2),
(min_identity = 0.97,), hashes_a)
b = build_manifest((reference = "PR2", version = "4.14.0", ladder = :pr2),
(min_identity = 0.99,), hashes_b)
validate_merge(a, b)
# MergeVerdict(refused: policy.min_identity differs: 0.97 vs 0.99;
# run.version differs: "5.0.0" vs "4.14.0")Inputs are expected to differ between runs — that is what pooling is for — so only the judgement surface is compared: the policy, and the reference, ladder and version. Hashes are recorded as your pipeline computed them and are never recomputed.
| Upstream / downstream | Exchange | Notes |
|---|---|---|
DADA2 |
TSV/CSV, one lineage column |
Join the per-rank columns into one |
QIIME 2 |
TSV, |
Detected automatically. Rank prefixes ( |
Astropy / ECSV |
ECSV |
The |
EPA-ng, pplacer, APPLES |
jplace v3 |
Read and written; all candidates kept. |
iTOL |
Newick + dataset files |
SIMPLEBAR (cumulative reads), MULTIBAR (factive / belief / residual), COLORSTRIP (contamination). |
ETE, treeio / ggtree ( |
Newick with NHX comments |
NHX-aware readers get rank, counts and status per node. The annotations sit
in |
DataFrames.jl, any Tables.jl sink |
NamedTuple of columns |
|
Protoctist does not reach back into any of these tools. It reads what they wrote. It does not re-sort, re-classify or re-hash anything. What it writes are standard formats that the next tool reads without a plugin.
The evidence vocabulary follows two formal developments, both checked in Agda
with --safe --without-K:
-
epistemic-types separates a factive modality, which has a reflection principle, from a belief modality, which deliberately lacks one.
FACTIVEandBELIEFfollow that split. A warrant there has noEvidence → Aconstructor. In the same way, Protoctist carries `EvidenceReceipt`s it is given and never mints one. -
residual-evidence-types quantifies identification over all admissible candidates.
LineageResidualis the count-level summary of that judgement.
The Julia types follow these designs; they are not extracted from the proofs.
-
EpistemicTypes.jl — receipts and merge checks in general form
-
Cladistics.jl — phylogenetic inference and Newick I/O (
PhylogeneticTree) -
EchoTypes.jl — specification tests
Protoctist 0.1 defines its own copies of the few shapes it needs from these, which is why it has no dependencies. Binding to them through package extensions is planned.
Cookbook (DADA2, QIIME 2, EPA-ng, pooling runs, all runnable
under examples/) · Lineage formats ·
Troubleshooting · Glossary
EXPLAINME gives the reasoning behind each design decision, the cost of each choice, and the current limits. Those limits are: a jplace reader that keeps only the five standard fields, no branch lengths on the taxonomy tree, and row matching that is linear in rows × depth × siblings.
julia --project=. -e 'using Pkg; Pkg.test()'100 behaviour tests across types, trees, file formats and manifests. They run after
Aqua.test_all (11 checks), which covers method ambiguities, unbound type
parameters, undefined exports, stale dependencies, compat bounds, type piracy
and persistent tasks.
Code, configuration and scripts are Mozilla Public License 2.0
(MPL-2.0); prose documentation is CC-BY-SA-4.0. Both texts live in
LICENSES/, and per-file SPDX-License-Identifier headers are authoritative.
The GitHub-detected licence is MPL-2.0 (the root LICENSE). Long-term
attribution uses Quantum-Safe Provenance — see
the Quantum-Safe Provenance exhibit.