
biocohort keeps the subjects, samples, and analysis outputs of a study in one validated object. Species and assays are values in the data, not columns or classes, so the same functions work for any organism and any omics assay.
See the repository root README for the motivation behind this package.
pak::pak("samuelbharti/biocohort/pkg-r")r-universe works too:
install.packages("biocohort", repos = "https://samuelbharti.r-universe.dev")A manifest is one long-format table, one row per sample. Four columns
carry the shape of the study: subject_id,
assay, sample_id, role. Every
other column is metadata.
subject_id,species,genotype,assay,sample_id,role
R1,rat,WT,wes,T1,tumor
R1,rat,WT,wes,N1,normal
R2,rat,KO,wes,T2,tumor
R2,rat,KO,wes,N2,normal
library(biocohort)
parsed <- read_manifest("manifest.csv")
cohort <- cohort_new(parsed$subject_tbl, parsed$sample_map)
cohort
#> ── Cohort
#> • 2 subjects (2 rat)
#> • 4 samples (4 wes)
subjects(cohort)
samples(cohort, assay = "wes")
completeness(cohort, wide = TRUE)Some studies keep one row per subject, with one id column per assay.
manifest_from_wide() turns that into the long form
first:
id_cols <- data.frame(
column = c("wes_tumor_id", "wes_normal_id"),
assay = c("wes", "wes"),
role = c("tumor", "normal")
)
long <- manifest_from_wide(wide_table, id_cols)read_manifest() reads
CSV, TSV, or Excel, always as text, so an id like 007 keeps
its leading zero. validate_manifest() checks it and splits
subject-level columns from sample-level ones.cohort_new() builds a
Cohort: one table of subjects, one long table of samples,
an optional Study, and a registry of analyses.subjects(),
samples(), completeness(), and
sample_pairs() return plain tibbles.
cohort_filter() keeps a subset and stays valid.cohort_qc() flags
or drops subjects or samples with a required reason.
qc_log() reads the audit trail, which survives later
cohort_filter() calls.cohort_groups()
groups subjects by one or more columns. cohort_contrasts()
enumerates every pairwise contrast between those groups.cohort_derive() bins an existing numeric column at named
cutoffs, so a cutoff is a value passed in, not code.
derive_log() reads its provenance.sample_sheet() writes the sample list a pipeline expects.
as_coldata() and join_metadata() carry cohort
metadata into a SummarizedExperiment, a Seurat object, or a
data frame.analysis_spec_new() and load_analysis()
resolve a path template per subject or pair, read the files, and record
which ones were found.apply_corrections() applies a table of documented overrides
to a manifest and keeps an audit trail, instead of a value changing
quietly inside a script.translate()
moves a feature table across genome builds or species, through a
liftover or an ortholog backend.read_study_yaml() builds a cohort from a YAML file that
names the study, the manifest, the paths, and the registered
analyses.The package website includes:
To build the site locally, run from the repository root:
pkgdown::build_site("pkg-r")See CONTRIBUTING.md for the development workflow.
MIT