Composition along dose#
How each cell type’s abundance responds to a dose, as its cells per other cell or its cells recovered per cell loaded, and which gene benchmark doses lie where a cell type is lost; Composition along dose explains the tests and benchmark doses, and Benchmark doses where a cell type is lost the flags.
How each cell type’s abundance responds to a dose, and the gene benchmark doses that lie where a cell type is lost.
A dose changes which cells a tissue holds, as well as what each cell expresses: after
TCDD, hepatocytes fell from 69% of mouse liver nuclei in the controls to 14% at 30
ug/kg, while macrophages rose from 10% to 39% (Nault et al. 2023).
composition_dose_response() tests each cell type’s cells per other cell
of its sample along dose, speckle’s logit of its proportion (Phipson et al. 2022) in
log2 units, or with cells_loaded its cells recovered per cell loaded, the viability
readout of hashed screens (Srivatsan et al. 2020), with the tests, gate, curves and
benchmark doses of dose_response()
(https://docs.nygen.io/CytePool/statistics/composition#composition-along-dose).
cell_loss_flags() marks the gene benchmark doses of a cell type that
lie at or above the lower bound of the dose at which its abundance falls: in vitro,
chemicals that killed cells in two viability assays activated a median of 12% of
815 assay endpoints against 1.3% for the others (Judson et al. 2016), so a response
there can be the cells’ dying
(https://docs.nygen.io/CytePool/statistics/potency#cell-loss-flags).
The values are fitted by limma’s linear model without observation weights, as
dose_response fits scores, with empirical Bayes moderation across the cell types,
robust as speckle’s propeller moderates them (Smyth 2004; Phipson et al. 2016).
Cell recovery falls both when cells die and when they divide less during an assay
(Hafner et al. 2016), and NTP caps an in vitro study’s top concentration at a 20% loss
of viability (NTP 2018).
References
Nault R, Saha S, Bhattacharya S, Sinha S, Maiti T, Zacharewski T (2023). Single-cell transcriptomics shows dose-dependent disruption of hepatic zonation by TCDD in mice. Toxicological Sciences 191, 135-148. doi:10.1093/toxsci/kfac109
Phipson B, Sim CB, Porrello ER, Hewitt AW, Powell J, Oshlack A (2022). propeller: testing for differences in cell type proportions in single cell data. Bioinformatics 38, 4720-4726. doi:10.1093/bioinformatics/btac582
Srivatsan SR, McFaline-Figueroa JL, Ramani V, et al. (2020). Massively multiplex chemical transcriptomics at single-cell resolution. Science 367, 45-51. doi:10.1126/science.aax6234
Judson R, Houck K, Martin M, et al. (2016). Analysis of the effects of cell stress and cytotoxicity on in vitro assay activity across a diverse chemical and assay space. Toxicological Sciences 152, 323-339. doi:10.1093/toxsci/kfw092
Smyth GK (2004). Linear models and empirical Bayes methods for assessing differential expression in microarray experiments. Statistical Applications in Genetics and Molecular Biology 3, article 3. doi:10.2202/1544-6115.1027
Phipson B, Lee S, Majewski IJ, Alexander WS, Smyth GK (2016). Robust hyperparameter estimation protects against hypervariable genes and improves power to detect differential expression. Annals of Applied Statistics 10, 946-963. doi:10.1214/16-AOAS920
Hafner M, Niepel M, Chung M, Sorger PK (2016). Growth rate inhibition metrics correct for confounders in measuring sensitivity to cancer drugs. Nature Methods 13, 521-527. doi:10.1038/nmeth.3853
NTP (2018). NTP research report on National Toxicology Program approach to genomic dose-response modeling. NTP Research Report 5. National Institute of Environmental Health Sciences. doi:10.22427/ntp-rr-5
- cytepool.composition_dose_response(data, design, *, dose, cells_loaded=None, tests=None, direction=None, spline_df=None, candidates=None, gate=None, models=None, variance=CONSTANT, bmr=None, averaging=None, n_resamples=None, robust=True, trend=False, batch=None, rng=None, n_threads=None)#
Test how each cell type’s abundance responds to a dose, and from which dose it changes.
Each cell type’s cells per other cell of its sample, speckle’s logit of its proportion in log2 units, are tested along dose as
dose_response()tests a cell type’s pathway scores: for sample j with x_j cells of the cell type, n_j cells in all and I cell types,v_j = log2((x_j + 1/2) / (n_j - x_j + (I - 1)/2)),
the log2 of q_j / (1 - q_j) for speckle’s proportion q_j = (x_j + 1/2) / (n_j + I/2). The tests are those of speckle’s
propelleron its logit, as t, F and p-values do not depend on the base of the logarithm; estimates and benchmark responses are in log2 units, as for genes. Withcells_loaded, each cell type’s cells recovered per cell loaded into the sample, L_j, are tested instead: cell recovery, v_j = log2((x_j + 1/2) / L_j), the viability readout of hashed screens (Srivatsan et al. 2020), which falls when cells die and when they divide less (Hafner et al. 2016). https://docs.nygen.io/CytePool/statistics/composition#composition-along-dose explains both.The values are fitted by dose_response’s model of the dose groups, limma’s linear model without observation weights, with empirical Bayes moderation across the cell types, robust by default as in
propeller(Phipson et al. 2016), where dose_response’s own default for scores is not robust. With fewer than 10 cell types the robust prior equals the ordinary one, and two cell types are not moderated. The tests, the gate, the curves ofmodels, their benchmark doses atbmrand the result’s methods are dose_response’s. With a handful of cell types and 2 to 4 replicates per dose, the gate calls cell types that do not change more often than its FDR allows, most often a cell type of a few cells per sample: on simulated series of 6 cell types, none changing, it called one or more in 14.6%, 10.7% and 6.4% of series at 2, 3 and 4 replicates, against the 5% it targets, and in 11.6%, 8.9% and 7.3% once the rarest, of 2 cells per sample, was left out.The benchmark dose of a cell type’s abundance:
bmr=BenchmarkResponse.absolute( numpy.log2(1.25))reads the dose at which the cell type’s cells per other cell, or per cell loaded, change 1.25-fold: a 20% fall or a 25% rise, with the direction beside each BMD. It is a descriptive potency: the ratio falls when the cell type’s cells are lost and also when the other cell types expand, and it depends on which cell types the data hold, since every other cell type counts towards the denominator. NTP caps an in vitro study’s top concentration at a 20% loss of viability (NTP 2018), a cap and not a benchmark response for abundance. The dose of a 50% loss of recovery is the BMD ofBenchmarkResponse.absolute(1.0), a halving; the EC50 of the table"ec50s"lies midway between the Hill curve’s plateaus in log2 units, which is not that dose. The bounds hold the true BMD less often than they claim: on simulated series where a dominant cell type’s ratio falls along a Hill curve, the best model’s BMDL of a 20% fall held it in 83% to 87% of series at 2 to 4 replicates when the replicates varied as little as the hepatocytes of TCDD-dosed mouse livers, and in 22% to 69% when they varied three times as much, where curves averaged over the models (averaging="akaike") held it in 47% to 77%; read a composition BMD as an order of magnitude.Exponential models need every dose-group mean above 0, so they are declined for a cell type whose mean log2 ratio is at or below 0 at any dose, which includes a dominant cell type that falls below half of the cells, and for recovery wherever a dose group recovers fewer cells than were loaded; the column
not_fitted_reasonof the table"curves"gives the reason. Their fits change with a shift of the values, so they depend on the unit ofcells_loaded, which counts cells. The tests, and the curves of the linear, polynomial 2, power and Hill models, do not depend on the cells loaded when every sample is loaded alike: the cells loaded then move only the curves’ level.Samples and cell types: the design’s samples are matched to those of the data by
sample_idand must all be among them. For composition, a sample without cells has no composition and is left out, and a cell type without cells in the samples used is left out; at least two cell types must remain. For recovery, a sample without cells is kept, a complete loss being data, at log2(1/2 / L_j), where the benchmark dose depends on the half cell added; a cell type without cells in any sample is left out. To test the composition of some cell types, such as one lineage, select them first (Cube.select(groups=...)), which changes every other cell type’s values.dose_response’s
rules,flagsandselectionare not taken: they apply guidance written for the curves of genes, and a composition BMD is a descriptive potency. Nor areanalysis, which reads counts, orgroups,min_cellsandmin_counts, which choose a cube’s cell types: select those first withCube.select(groups=...).- Parameters:
data – The number of cells of every sample in every cell type, as whole numbers: a
Cubethat records them (n_cells), such asfrom_cells()builds, or a table with one row per sample, a text columnsample_idand one column of cell numbers per cell type, aspropeller()takes it.design – A
Designof the terms other than dose, such asDesign(cube.samples, "~ 1")or"~ sex", whose sample table has asample_idcolumn with sample ids of the data and the dose column. Random effects are refused: the fit has fixed effects only, as inpropeller. With other terms, curves needvariance="weighted"or"moderated", which fit the dose-group means adjusted for them.dose – The
DoseAxisof the series.cells_loaded – None (default) to test composition; or the name of a numeric column of the design’s samples holding the number of cells loaded into each sample, in cells, such as the cells seeded into its well or loaded onto its channel, finite and above 0, to test recovery. A sample may recover more cells than were loaded, when they divide during the assay.
tests – The tests, as in
dose_response(); None (default) for the spline, nonlinearity, linear trend and dose-group tests the design supports.direction –
"up"or"down"for one-sided tests of the tests with a sign, as in dose_response; None (default) for two-sided tests.spline_df – The spline’s columns, as in dose_response; None (default) for 2 with 4 doses or more on the axis, 1 otherwise.
candidates – The candidate shapes of
"mcp", as in dose_response; None (default) spreads the default shapes over the design’s doses.gate – The gate’s
"test"and"fdr", as in dose_response; None (default) for the spline test at 5% FDR across the cell types. A fold change is refused: read the size of a change from benchmark doses.models – A set of dose-response models, as in dose_response, such as
"epa"; None (default) for no curves.variance –
"constant"(default),"weighted"or"moderated", as in dose_response.bmr – The benchmark response, a
BenchmarkResponseor a list of them, as in dose_response; None (default) for none. Needsmodels.averaging – None (default), or
"akaike"for curves averaged over the set’s models, as in dose_response.n_resamples – The resamples of the bootstrap of curves, as in dose_response; None (default) for 1,000.
robust – Whether the moderation’s prior is estimated robustly, True by default, as
propellerand limma’seBayes(robust = TRUE)do.trend – Whether the prior variance follows the mean value of the cell types, as limma’s
eBayes(trend = TRUE); False by default, as inpropeller.batch – A column of the design’s samples naming each sample’s processing batch, which the design check reads, as in dose_response.
rng – A numpy random generator, an integer seed, or None, for the multiple contrast tests and the bootstrap of curves, as in dose_response.
n_threads – The most threads for the multiple contrast tests and the curves; None for numba’s default.
- Returns:
A
DoseResponseResultof one group,"composition", or"recovery"withcells_loaded, whose tables have one row per cell type tested, named in the columncell_type, with the columns dose_response gives scores:estimate, the change from the vehicle in log2 units, andaverage, the mean value over the samples fitted. The cell types are rows of that group, so pass them asgenestocurve()andplot_dose_response(); the summary’sn_genes_passing_gatecounts the cell types that pass the gate, and the table oftarget_doses()names them infeature_id. Benjamini-Hochberg adjusts each test over the cell types, so the tables have noadjusted_p_value_across_groups.provenance["scores"]records the values:type("composition"or"recovery"),method("composition_dose_response"),settings(cells_added, the half cell added to every count;cells_loaded; andinput,"cube"or"table"),names, the cell types tested, andleft_out, those without cells, with the reason, which the printout lists too;provenance["cube"]identifies the cube, or the table as the cube without features that holds it.- Raises:
TypeError – If
datais not a cube with cell numbers or a table of them, a column of cell numbers does not hold integers,designis not a Design,cells_loadedis not a column name or names a column that does not hold numbers,robustortrendis not True or False, or as dose_response raises for its options.ValueError – If the cube records no cell numbers, the table is not one of cell numbers, the design has random effects or names samples the data do not have,
cells_loadednames no column of the design’s samples or a value that is not finite and above 0, fewer than two cell types have cells for composition or none for recovery, a sample has 2**53 cells or more, the gate has a fold change, or as dose_response raises.
Used in: Dose response per cell type
Explained in: Choosing a method, Composition tests, Potency and points of departure
- cytepool.cell_loss_flags(result, group=None, *, abundance)#
Flag the benchmark doses of a cell type’s genes that lie where the cell type is lost.
A curve at high doses describes the cells that survived, so a gene’s benchmark dose (BMD) in a range where the cell type’s abundance falls can measure the cells’ dying rather than a response of the cells: in vitro, chemicals positive in two viability assays activated a median of 12% of 815 assay endpoints against 1.3% for the others (Judson et al. 2016). The loss range of a cell type starts at the BMDL, the lower bound, of its abundance’s BMD in a
composition_dose_response()result, of its composition or, withcells_loaded, of its recovery, where the cell type passes that result’s gate and its BMD is a fall; a gene’s BMD at or above it lies in the loss range, a dose at which the data cannot rule out that the cell type has lost cells. The gate keeps out the falls that the tests do not find: curves are fitted to every cell type, and on simulated series where no cell type changed, the best model’s curve fell with a BMDL for 13 of 30 cell types, none of which passed the gate. That BMDL holds the true BMD less often than it claims, so a range can start late: read it from curves averaged over the models (averaging="akaike"), whose bounds hold it more often where replicates vary much. https://docs.nygen.io/CytePool/statistics/potency#cell-loss-flags explains how to read the flags.- Parameters:
result – A
DoseResponseResultwith benchmark doses, of a cube’s genes or of a cell type’s pathway scores or activities.group – A cell type of
result; it may be left out when the result checked one.abundance – The
composition_dose_response()result of the same samples, of the composition or, withcells_loaded, of the recovery, with benchmark doses at one BMR, such asBenchmarkResponse.absolute(numpy.log2(1.25)), and their bounds, on a dose axis of the same unit and metric, among whose cell types isgroup.
- Returns:
The table
"benchmark_doses"ofgroupinresult, with two columns more:loss_bmdl, the BMDL of the cell type’s abundance at the BMR ofabundancewhere the cell type passes the gate ofabundanceand its BMD is a fall (direction"down"), NaN where it does not pass that gate, rises, does not reach the BMR or has no bound; andin_loss_range, whether the row’s BMD is at or aboveloss_bmdl, False where either is NaN.- Raises:
TypeError – If
resultorabundanceis not a DoseResponseResult, orgroupis not a string.ValueError – If
resulttests the composition or recovery of cell types,abundancedoes not or has no benchmark doses, more than one BMR or no bounds, the two dose axes differ in unit or metric, a sample ofgroupinresultis not a sample ofabundanceat the same dose, orgroupis left out andresultchecked several cell types.KeyError – If
groupwas not checked inresultor has no benchmark doses there, the gate did not run inabundance, orgroupis not among the cell typesabundancetested; the message lists them.
Used in: Dose response per cell type
Explained in: Choosing a method, Potency and points of departure