Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ visible.

[source,julia]
----
b = Protoctist.IO.read_jplace("epa_result.jplace")
b = Protoctist.Formats.read_jplace("epa_result.jplace")
b.placements # every candidate edge for every query
Protoctist.IO.best_placements(b) # one per query, highest like_weight_ratio
Protoctist.IO.write_jplace(b, "filtered.jplace")
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`).
Expand Down Expand Up @@ -179,7 +179,7 @@ recomputed.

| DataFrames.jl, any Tables.jl sink
| NamedTuple of columns
| `DataFrame(Protoctist.IO.columntable(Protoctist.IO.read_ecsv(path)))`.
| `DataFrame(Protoctist.Formats.columntable(Protoctist.Formats.read_ecsv(path)))`.
|===

Protoctist does not reach back into any of these tools. It reads what they
Expand Down Expand Up @@ -233,7 +233,7 @@ branch lengths on the taxonomy tree, and row matching that is linear in rows
julia --project=. -e 'using Pkg; Pkg.test()'
----

100 behaviour tests across types, trees, IO and manifests. They run after
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.
Expand Down
10 changes: 5 additions & 5 deletions docs/ARCHITECTURE.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ inventory is link:architecture/REPOSITORY-MAP.adoc[REPOSITORY-MAP].

----
lineage table (ECSV / CSV) jplace (EPA-ng, pplacer)
│ IO.read_ecsv │ IO.read_jplace
│ Formats.read_ecsv │ Formats.read_jplace
▼ ▼
ProtistRun ── TaxPath per row PlacementBatch ── best_placements
│
Expand All @@ -20,7 +20,7 @@ lineage table (ECSV / CSV) jplace (EPA-ng, pplacer)
▼
TaxonomyTree + NodeAnnot
│ Tree.annotate_newick (NHX in bracket comments)
│ IO.export_itol_bundle
│ Formats.export_itol_bundle
▼
Newick, iTOL datasets, ECSV Manifest.build_manifest / validate_merge
----
Expand Down Expand Up @@ -53,8 +53,8 @@ enter or leave at any point.
| `TaxonomyTree` (a trie keyed by `(label, rank)`), `NodeAnnot`,
`build_taxonomy_tree`, `rollup_counts`, `annotate_newick`.

| `IO`
| `src/io.jl`
| `Formats`
| `src/formats.jl`
| `ECSVTable`, `read_ecsv`/`write_ecsv` (header comments kept verbatim),
`columntable` (the Tables.jl column-table shape), `read_jplace`/`write_jplace`
(every placement of every query), `best_placements` (highest
Expand All @@ -80,7 +80,7 @@ planned as package extensions and is not in 0.1.

`test/runtests.jl` runs `Aqua.test_all` first, then every
`test/cases/*.jl` in sorted order: one file per source module (`types.jl`,
`tree.jl`, `io.jl`, `manifest.jl`), `examples.jl`, which runs each
`tree.jl`, `formats.jl`, `manifest.jl`), `examples.jl`, which runs each
`examples/*/run.jl`, and `smoke.jl`. The worked examples under `examples/`
(`dada2/`, `qiime2/`, `epa-ng/`) are therefore tested and cannot drift from the
code.
Expand Down
14 changes: 7 additions & 7 deletions docs/EXPLAINME.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ turns that into a loop.
=== D10. No package dependencies

*Decision.* `[deps]` in `Project.toml` is empty. ECSV, CSV/TSV and jplace are
read and written by code in `src/io.jl`.
read and written by code in `src/formats.jl`.

*Why.* A package that enters an existing analysis environment should not be
able to change the resolution of anything already there. With no dependencies,
adding Protoctist cannot downgrade CSV.jl, JSON3.jl or DataFrames.jl in your
environment. A Tables.jl-shaped escape hatch covers users who want a
DataFrame: `DataFrame(Protoctist.IO.columntable(Protoctist.IO.read_ecsv(p)))`.
DataFrame: `DataFrame(Protoctist.Formats.columntable(Protoctist.Formats.read_ecsv(p)))`.

*Cost.* The file readers are written for the formats as pipelines emit them,
not as general parsers. The limits below list where that matters.
Expand Down Expand Up @@ -295,7 +295,7 @@ strip that header.

| DataFrames.jl, any Tables.jl sink
| NamedTuple of columns
| `Protoctist.IO.columntable`.
| `Protoctist.Formats.columntable`.
|===

== What it deliberately does not do
Expand Down Expand Up @@ -350,11 +350,11 @@ tests that pin each decision are:

| D1, D2 | `types.jl` — "TaxPath — ladders, ranks, truncation"
| D3, D4, D5 | `tree.jl`
| D4 (counts) | `io.jl` — "counts are never silently zeroed; TSV loads"
| D4 (counts) | `formats.jl` — "counts are never silently zeroed; TSV loads"
| D9 | `manifest.jl`
| D11 | `io.jl` — "jplace keeps every candidate placement"
| D12 | `io.jl` — "iTOL bundle + run pipeline"
| D13 | `io.jl` — "ECSV round-trip", "a field containing the separator round-trips"
| D11 | `formats.jl` — "jplace keeps every candidate placement"
| D12 | `formats.jl` — "iTOL bundle + run pipeline"
| D13 | `formats.jl` — "ECSV round-trip", "a field containing the separator round-trips"
|===

Where a decision fixed an earlier defect (D2's trailing separator, D4's count
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/cookbook.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Load `tree.newick` into iTOL and drag the three dataset files onto the tree.
`load_protist_run` rolls up counts only, so the status and contamination files
are all zeros here. To fill them, build rows that carry a `status` and a
`residual`, roll them up with `rollup_counts`, and write the files with
`Protoctist.IO.export_itol_bundle(tree, annot, "out")`. The README section on
`Protoctist.Formats.export_itol_bundle(tree, annot, "out")`. The README section on
evidence status shows the row shape.

The counts summed here are over all samples. For one tree per sample, write one
Expand Down Expand Up @@ -103,7 +103,7 @@ placement for every query, and for `nm` entries every name:
[source,julia]
----
using Protoctist
const PIO = Protoctist.IO
const PIO = Protoctist.Formats

b = PIO.read_jplace("epa_result.jplace")
length(b.placements) # 4: ASV1 on two edges, ASV2 and ASV7 sharing one
Expand Down
2 changes: 1 addition & 1 deletion examples/epa-ng/run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Run from this directory: julia --project=../.. run.jl

using Protoctist
const PIO = Protoctist.IO
const PIO = Protoctist.Formats

b = PIO.read_jplace("epa_result.jplace")
println(length(b.placements), " candidate placements")
Expand Down
16 changes: 8 additions & 8 deletions src/Protoctist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ no extension ships in this release.

- [`Protoctist.Types`](@ref) — `TaxPath`, `EvidenceReceipt`, `EpiStatus`, …
- [`Protoctist.Tree`](@ref) — taxonomy trees, evidence rollup, Newick
- [`Protoctist.IO`](@ref) — ECSV, jplace, iTOL bundles
- [`Protoctist.Formats`](@ref) — ECSV, jplace, iTOL bundles
- [`Protoctist.Manifest`](@ref) — run manifests and the merge check
"""
module Protoctist

# --- submodules (order matters: IO uses Tree) ----------------------------
# --- submodules (order matters: Formats uses Tree) ----------------------------
include("types.jl")
include("tree.jl")
include("io.jl")
include("formats.jl")
include("manifest.jl")

using .Types
Expand All @@ -50,7 +50,7 @@ using .Manifest

# --- public API ----------------------------------------------------------

export Types, Tree, IO, Manifest
export Types, Tree, Formats, Manifest
export TaxPath,
EvidenceReceipt,
EpiStatus,
Expand Down Expand Up @@ -78,7 +78,7 @@ One loaded protist run: the source table, the taxonomy tree built from its
lineages, and the evidence rolled up over that tree.
"""
struct ProtistRun
table::IO.ECSVTable
table::Formats.ECSVTable
tree::Tree.TaxonomyTree
annot::Tree.NodeAnnot
ladder::Symbol
Expand Down Expand Up @@ -116,7 +116,7 @@ function load_protist_run(
count = nothing,
sep::Char = ',',
)
t = IO.read_ecsv(path; sep = sep)
t = Formats.read_ecsv(path; sep = sep)
lincol =
lineage === nothing ? _detect(t, ("lineage", "taxonomy", "taxpath", "taxon")) :
String(lineage)
Expand Down Expand Up @@ -153,7 +153,7 @@ function _parsecount(s::AbstractString, row::Int, col::AbstractString, path::Abs
)
end

function _detect(t::IO.ECSVTable, candidates)
function _detect(t::Formats.ECSVTable, candidates)
for c in candidates
i = findfirst(n -> lowercase(n) == c, t.names)
i === nothing || return t.names[i]
Expand Down Expand Up @@ -190,6 +190,6 @@ also be dropped onto an IQ-TREE phylogeny in iTOL wherever its tip or node
labels use the same taxon names. The name follows the recovered design.
"""
export_iqtree_annotated(run::ProtistRun, outdir::AbstractString) =
IO.export_itol_bundle(run.tree, run.annot, outdir)
Formats.export_itol_bundle(run.tree, run.annot, outdir)

end # module Protoctist
8 changes: 4 additions & 4 deletions src/io.jl → src/formats.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: MPL-2.0
# Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
#
# Protoctist.IO — the file formats protist pipelines actually exchange.
# Protoctist.Formats — the file formats protist pipelines actually exchange.
#
# Recovered API (design thread, 2026-09-16):
# read_ecsv(path)::DataFrame write_ecsv(df, path)
Expand All @@ -12,10 +12,10 @@
# dependency: the core must load in a bare environment. `read_ecsv` returns an
# `ECSVTable`; `columntable(t)` turns it into a NamedTuple of vectors, which is
# the Tables.jl column-table shape every DataFrame constructor accepts, so
# `DataFrame(Protoctist.IO.columntable(read_ecsv(p)))` gives the design's
# `DataFrame(Protoctist.Formats.columntable(read_ecsv(p)))` gives the design's
# DataFrame without imposing the dependency on users who do not want it.

module IO
module Formats

using ..Types
using ..Tree: annotate_newick, TaxonomyTree, NodeAnnot
Expand Down Expand Up @@ -486,4 +486,4 @@ function export_itol_bundle(tree::TaxonomyTree, annot::NodeAnnot, outdir::Abstra
return written
end

end # module IO
end # module Formats
30 changes: 15 additions & 15 deletions test/cases/io.jl → test/cases/formats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
"Eukaryota;Excavata;Metamonada,odd",3
""",
)
t = Protoctist.IO.read_ecsv(p)
t = Protoctist.Formats.read_ecsv(p)
@test t.names == ["lineage", "count"]
@test length(t) == 2
# a comma inside a quoted field must survive
@test t["lineage"][2] == "Eukaryota;Excavata;Metamonada,odd"
@test length(t.meta) == 3 # header preserved

q = joinpath(dir, "out.ecsv")
Protoctist.IO.write_ecsv(t, q)
t2 = Protoctist.IO.read_ecsv(q)
Protoctist.Formats.write_ecsv(t, q)
t2 = Protoctist.Formats.read_ecsv(q)
@test t2.names == t.names
@test t2.columns == t.columns
@test t2.meta == t.meta
Expand All @@ -45,7 +45,7 @@ end
}
""",
)
b = Protoctist.IO.read_jplace(p)
b = Protoctist.Formats.read_jplace(p)
@test b.version == 3
@test occursin("{0}", b.tree)
@test length(b.placements) == 2
Expand All @@ -55,8 +55,8 @@ end
@test b.placements[2].name == "query2"

q = joinpath(dir, "out.jplace")
Protoctist.IO.write_jplace(b, q)
b2 = Protoctist.IO.read_jplace(q)
Protoctist.Formats.write_jplace(b, q)
b2 = Protoctist.Formats.read_jplace(q)
@test b2.tree == b.tree
@test length(b2.placements) == length(b.placements)
@test b2.placements[1].name == "query1"
Expand Down Expand Up @@ -85,7 +85,7 @@ end
}
""",
)
b = Protoctist.IO.read_jplace(p)
b = Protoctist.Formats.read_jplace(p)
@test length(b.placements) == 5
q1 = filter(x -> x.name == "query1", b.placements)
@test [x.edge_num for x in q1] == [0, 1]
Expand All @@ -98,17 +98,17 @@ end
@test q3.like_weight_ratio ≈ 0.5 # columns after the null stay aligned
@test q3.pendant_length ≈ 0.1

best = Protoctist.IO.best_placements(b)
best = Protoctist.Formats.best_placements(b)
@test [x.name for x in best] == ["query1", "query2a", "query2b", "query3"]
@test best[1].edge_num == 1 # highest LWR, not first listed
@test best[1].like_weight_ratio ≈ 0.65

q = joinpath(dir, "out.jplace")
Protoctist.IO.write_jplace(b, q)
Protoctist.Formats.write_jplace(b, q)
out = read(q, String)
@test !occursin("NaN", out) # JSON has no NaN
@test count("\"n\":", out) == 4 # one object per query
b2 = Protoctist.IO.read_jplace(q)
b2 = Protoctist.Formats.read_jplace(q)
@test length(b2.placements) == length(b.placements)
@test [(x.name, x.edge_num) for x in b2.placements] == [(x.name, x.edge_num) for x in b.placements]
@test isnan(only(filter(x -> x.name == "query3", b2.placements)).likelihood)
Expand Down Expand Up @@ -185,15 +185,15 @@ end
@testset "a field containing the separator round-trips" begin
mktempdir() do dir
# QIIME 2 lineages contain spaces; Astropy ECSV is space-delimited.
t = Protoctist.IO.ECSVTable(
t = Protoctist.Formats.ECSVTable(
["taxonomy", "reads"],
[["d__Eukaryota; p__Cercozoa", "a\tb"], ["4", "2"]],
["# %ECSV 1.0"],
)
for sep in (' ', '\t', ',')
p = joinpath(dir, "sep.ecsv")
Protoctist.IO.write_ecsv(t, p; sep = sep)
@test Protoctist.IO.read_ecsv(p; sep = sep).columns == t.columns
Protoctist.Formats.write_ecsv(t, p; sep = sep)
@test Protoctist.Formats.read_ecsv(p; sep = sep).columns == t.columns
end
end
end
Expand Down Expand Up @@ -223,7 +223,7 @@ end
}
""",
)
b = Protoctist.IO.read_jplace(p)
b = Protoctist.Formats.read_jplace(p)
@test length(b.placements) == 4
q1 = filter(x -> x.name == "query1", b.placements)
@test [x.edge_num for x in q1] == [0, 1]
Expand All @@ -249,7 +249,7 @@ end
}
""",
)
best = Protoctist.IO.best_placements(Protoctist.IO.read_jplace(p))
best = Protoctist.Formats.best_placements(Protoctist.Formats.read_jplace(p))
@test only(filter(x -> x.name == "first_null", best)).edge_num == 1
# With no number to compare, the first listed is kept.
@test only(filter(x -> x.name == "all_null", best)).edge_num == 0
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# cleanly, whose deps are not compat-closed, or whose exports are
# ambiguous is rejected before any behaviour test can pass.
# 2. Behaviour — every test/cases/*.jl is included, in sorted order. There is
# one file per source module (types, tree, io, manifest); io.jl covers
# one file per source module (types, tree, formats, manifest); formats.jl covers
# the lineage tables, jplace and the exporters, manifest.jl the
# manifest and merge check, examples.jl runs examples/*/run.jl. smoke.jl
# is only the load check.
Expand Down
Loading