foldChange
foldChange ¶
foldChange(
data,
fromGroup,
toGroup=None,
imageId="imageid",
phenotype="phenotype",
normalize=True,
subsetPhenotype=None,
label="foldchange",
verbose=True,
outputDir=None,
streamData=False,
sdataTable=None,
)
Fold change in cell-type abundance between samples.
Counts each phenotype per sample, normalises by the sample's total cell count
when normalize=True, and divides every target group by the reference group.
Significance comes from a Fisher exact test on the raw counts.
Two tables are written: uns[label + "_fc"] holds the fold changes and
uns[label + "_pval"] the p-values, both group x phenotype. Plot them with
sp.pl.foldChange.
Normalisation matters here. Without it, a sample with twice as many cells looks enriched for everything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
(AnnData | SpatialData | str, required)
|
The cell table. An |
required |
fromGroup
|
(str | list, required)
|
The reference sample(s) — the denominator of every ratio. |
required |
toGroup
|
str | list
|
The sample(s) to compare against the reference. |
None
|
imageId
|
str
|
Column in |
'imageid'
|
phenotype
|
str
|
Column in |
'phenotype'
|
normalize
|
bool
|
Divide each group's counts by its total cell number before taking the ratio. Leave this on unless the groups are already the same size. |
True
|
subsetPhenotype
|
list
|
Restrict the analysis to these cell types. |
None
|
label
|
str
|
Prefix for the two |
'foldchange'
|
verbose
|
bool
|
Print progress messages. |
True
|
outputDir
|
str
|
Directory to write the updated object to. With |
None
|
streamData
|
bool
|
Run out of core against an |
False
|
sdataTable
|
str
|
Which |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
adata |
AnnData | SpatialData | None
|
The updated object with |
Example
adata = sp.tl.foldChange(adata, fromGroup="control", phenotype="phenotype")
adata.uns["foldchange_fc"]
adata.uns["foldchange_pval"]
sp.pl.foldChange(adata, method="heatmap")
# Two named arms only, immune cell types only.
adata = sp.tl.foldChange(
adata,
fromGroup="untreated",
toGroup=["treated_day7", "treated_day21"],
subsetPhenotype=["Treg", "NK cells", "Dendritic cells"],
)