diff --git a/README.adoc b/README.adoc index 7e1f448..875521a 100644 --- a/README.adoc +++ b/README.adoc @@ -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`). @@ -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 @@ -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. diff --git a/docs/ARCHITECTURE.adoc b/docs/ARCHITECTURE.adoc index eb1f3cc..36d5ec1 100644 --- a/docs/ARCHITECTURE.adoc +++ b/docs/ARCHITECTURE.adoc @@ -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 │ @@ -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 ---- @@ -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 @@ -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. diff --git a/docs/EXPLAINME.adoc b/docs/EXPLAINME.adoc index eb7bed3..c286d92 100644 --- a/docs/EXPLAINME.adoc +++ b/docs/EXPLAINME.adoc @@ -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. @@ -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 @@ -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 diff --git a/docs/guide/cookbook.adoc b/docs/guide/cookbook.adoc index 7a19d69..d23f797 100644 --- a/docs/guide/cookbook.adoc +++ b/docs/guide/cookbook.adoc @@ -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 @@ -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 diff --git a/examples/epa-ng/run.jl b/examples/epa-ng/run.jl index eb8ca30..02e151e 100644 --- a/examples/epa-ng/run.jl +++ b/examples/epa-ng/run.jl @@ -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") diff --git a/src/Protoctist.jl b/src/Protoctist.jl index a8af87e..19b4c33 100644 --- a/src/Protoctist.jl +++ b/src/Protoctist.jl @@ -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 @@ -50,7 +50,7 @@ using .Manifest # --- public API ---------------------------------------------------------- -export Types, Tree, IO, Manifest +export Types, Tree, Formats, Manifest export TaxPath, EvidenceReceipt, EpiStatus, @@ -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 @@ -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) @@ -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] @@ -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 diff --git a/src/io.jl b/src/formats.jl similarity index 98% rename from src/io.jl rename to src/formats.jl index bf15667..0eba392 100644 --- a/src/io.jl +++ b/src/formats.jl @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MPL-2.0 # Copyright (c) 2026 Jonathan D.A. Jewell # -# 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) @@ -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 @@ -486,4 +486,4 @@ function export_itol_bundle(tree::TaxonomyTree, annot::NodeAnnot, outdir::Abstra return written end -end # module IO +end # module Formats diff --git a/test/cases/io.jl b/test/cases/formats.jl similarity index 91% rename from test/cases/io.jl rename to test/cases/formats.jl index d9838e9..bd3296f 100644 --- a/test/cases/io.jl +++ b/test/cases/formats.jl @@ -12,7 +12,7 @@ "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 @@ -20,8 +20,8 @@ @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 @@ -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 @@ -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" @@ -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] @@ -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) @@ -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 @@ -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] @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 4f76039..c664eb2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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.