| Title: | Perturbation Analysis for Cell Painting Data |
|---|---|
| Description: | This package load cell painting data into R and preprocess feature to make them ready for machine learning. We use random forest to predict cell perturbations from CellProfiler features. We summarize the results in a volcano plot. |
| Authors: | Christof Seiler [aut, cre] (ORCID: <https://orcid.org/0000-0001-8802-3642>), Phatthamon Laphanuwat [ctb], Caroline Ospelt [ctb], European League Against Rheumatism [fnd], Swiss National Science Foundation [fnd] |
| Maintainer: | Christof Seiler <[email protected]> |
| License: | LGPL-3 |
| Version: | 0.99.0 |
| Built: | 2026-07-13 11:49:34 UTC |
| Source: | https://github.com/BiocStaging/cellpaintr |
Aggregate predicted leave-one-out probabilities over meta variables
aggregateYhat(sce, target, group, assay_type = "tfmfeatures")aggregateYhat(sce, target, group, assay_type = "tfmfeatures")
sce |
|
target |
Name of target variable for prediction |
group |
Grouping variable for cross-validation, e.g., patient |
assay_type |
A string specifying the assay |
data.frame
Aggregate predicted leave-one-out probabilities over meta variables over a list of SingleCellExperiment objects
calculateStats(sce, target, group, assay_type = "tfmfeatures")calculateStats(sce, target, group, assay_type = "tfmfeatures")
sce |
A |
target |
Name of target variable for prediction |
group |
Grouping variable for cross-validation, e.g., patient |
assay_type |
A string specifying the assay |
data.frame
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 ) calculateStats(sce_single, target = "Drug", group = "Patient")set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 ) calculateStats(sce_single, target = "Drug", group = "Patient")
Internal function to compute y_hat on a subset of the features
compute_y_hat( feature_name, sce_feature, starts, target, group, interest_level, reference_level, weights, n_threads, assay_type )compute_y_hat( feature_name, sce_feature, starts, target, group, interest_level, reference_level, weights, n_threads, assay_type )
feature_name |
String with feature name |
sce_feature |
|
starts |
Starting string |
target |
Name of target variable for prediction |
group |
Grouping variable for cross-validation, e.g., patient |
interest_level |
Factor interest level in 'target' variable |
reference_level |
Factor reference level in 'target' variable |
weights |
Weights variable when features are aggregated |
n_threads |
Number of parallel threads for fitting of models |
assay_type |
A string specifying the assay |
tibble data frame
Simulate CellProfiler data and write to a temporary file
generate_data()generate_data()
path to csv file
set.seed(23) generate_data()set.seed(23) generate_data()
Load cell painting data from file and convert to a SingleCellExperiment
loadData(cell_file)loadData(cell_file)
cell_file |
path to csv file from CellProfiler, e.g., MyExpt_Cells.csv |
SingleCellExperiment object
set.seed(23) cell_file <- generate_data() loadData(cell_file)set.seed(23) cell_file <- generate_data() loadData(cell_file)
Plot AUC comparison
plotAUC(sce, target, group, assay_type = "tfmfeatures")plotAUC(sce, target, group, assay_type = "tfmfeatures")
sce |
A |
target |
Name of target variable for prediction |
group |
Grouping variable for cross-validation, e.g., patient |
assay_type |
A string specifying the assay |
ggplot2 object
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 ) plotAUC(sce_single, target = "Drug", group = "Patient")set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 ) plotAUC(sce_single, target = "Drug", group = "Patient")
Plot number of cells per image
plotCellsPerImage(sce, bins = 100)plotCellsPerImage(sce, bins = 100)
sce |
|
bins |
Number of histogram bins |
ggplot2 object
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) plotCellsPerImage(sce)set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) plotCellsPerImage(sce)
Plot predicted leave-one-out probabilities
plotLOO(sce, target, group, assay_type = "tfmfeatures")plotLOO(sce, target, group, assay_type = "tfmfeatures")
sce |
|
target |
Name of target variable for prediction |
group |
Grouping variable for cross-validation, e.g., patient |
assay_type |
A string specifying the assay |
ggplot2 object
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 ) plotLOO(sce_single, target = "Drug", group = "Patient")set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 ) plotLOO(sce_single, target = "Drug", group = "Patient")
Plot number of cells per image
plotPCACor( sce, filter_by = 1, top = 20, pcs = seq(5), assay_type = "tfmfeatures" )plotPCACor( sce, filter_by = 1, top = 20, pcs = seq(5), assay_type = "tfmfeatures" )
sce |
|
filter_by |
PC to use for feature selection |
top |
Number of top features to select |
pcs |
Number of PCs to plot |
assay_type |
A string specifying the assay |
ggplot2 object
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce, robust = TRUE) sce <- scater::runPCA(sce, exprs_values = "tfmfeatures", ncomponents = 10) plotPCACor(sce, filter_by = 1)set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce, robust = TRUE) sce <- scater::runPCA(sce, exprs_values = "tfmfeatures", ncomponents = 10) plotPCACor(sce, filter_by = 1)
Plot ROC curves
plotROC(sce, target, group, assay_type = "tfmfeatures")plotROC(sce, target, group, assay_type = "tfmfeatures")
sce |
|
target |
Name of target variable for prediction |
group |
Grouping variable for cross-validation, e.g., patient |
assay_type |
A string specifying the assay |
ggplot2 object
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 ) plotROC(sce_single, target = "Drug", group = "Patient")set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 ) plotROC(sce_single, target = "Drug", group = "Patient")
Predict target from features
predictLOO( sce, target, group, interest_level, reference_level, types = NULL, channels = NULL, weights = NULL, n_threads = 1, assay_type = "tfmfeatures" )predictLOO( sce, target, group, interest_level, reference_level, types = NULL, channels = NULL, weights = NULL, n_threads = 1, assay_type = "tfmfeatures" )
sce |
|
target |
Name of target variable for prediction |
group |
Grouping variable for cross-validation, e.g., patient |
interest_level |
Factor interest level in 'target' variable |
reference_level |
Factor reference level in 'target' variable |
types |
Vector of strings of feature types |
channels |
Vector of strings of feature channels |
weights |
Weights variable when features are aggregated |
n_threads |
Number of parallel threads for fitting of models |
assay_type |
A string specifying the assay |
tibble data frame
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 )set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 )
Filter low variance features
removeLowVariance(sce, threshold = 0, robust = FALSE)removeLowVariance(sce, threshold = 0, robust = FALSE)
sce |
|
threshold |
Keep features that have larger variance than this threshold |
robust |
If true use median absolute deviation, otherwise use variance |
SingleCellExperiment object
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- removeLowVariance(sce)set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- removeLowVariance(sce)
Remove cells with missing features
removeNAs(sce)removeNAs(sce)
sce |
|
SingleCellExperiment object
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- removeNAs(sce)set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- removeNAs(sce)
Remove cells if not enough or too many in one image
removeOutliers(sce, min, max)removeOutliers(sce, min, max)
sce |
|
min |
Remove cells below that number |
max |
Remove cells above that number |
SingleCellExperiment object
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- removeOutliers(sce, min = 0, max = 300)set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- removeOutliers(sce, min = 0, max = 300)
Remove zero-inflated features
removeZeroInflation(sce, proportion = 0.2)removeZeroInflation(sce, proportion = 0.2)
sce |
|
proportion |
Remove features exceeding this zero-inflation proportion |
SingleCellExperiment object
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- removeZeroInflation(sce)set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- removeZeroInflation(sce)
Filter low variance features
transformLogScale(sce, robust = FALSE)transformLogScale(sce, robust = FALSE)
sce |
|
robust |
If true robust z-score, otherwise standard z-score |
SingleCellExperiment object
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce)set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce)
Plot predicted leave-one-out probabilities
volcanoPlot( sce, target, group, p_cutoff = NULL, fc_cutoff = 1, assay_type = "tfmfeatures" )volcanoPlot( sce, target, group, p_cutoff = NULL, fc_cutoff = 1, assay_type = "tfmfeatures" )
sce |
A |
target |
Name of target variable for prediction |
group |
Grouping variable for cross-validation, e.g., patient |
p_cutoff |
Cut-off for statistical significance. A horizontal line will be drawn at -log10(p_cutoff). |
fc_cutoff |
Cut-off for absolute log2 fold-change. A vertical lines will be drawn at fc_cutoff. |
assay_type |
A string specifying the assay |
ggplot2 object
set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 ) volcanoPlot(sce_single, target = "Drug", group = "Patient", p_cutoff = 0.05, fc_cutoff = 0.5 )set.seed(23) cell_file <- generate_data() sce <- loadData(cell_file) sce <- transformLogScale(sce) sce$Drug <- as.factor(sce$Drug) sce$Drug <- relevel(sce$Drug, ref = "D1") types <- c("AreaShape", "Intensity", "Texture") sce_single <- predictLOO( sce, target = "Drug", group = "Patient", interest_level = "D7", reference_level = "D1", types = types, n_threads = 1 ) volcanoPlot(sce_single, target = "Drug", group = "Patient", p_cutoff = 0.05, fc_cutoff = 0.5 )