Package 'cellpaintr'

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

Help Index


Aggregate predicted leave-one-out probabilities over meta variables

Description

Aggregate predicted leave-one-out probabilities over meta variables

Usage

aggregateYhat(sce, target, group, assay_type = "tfmfeatures")

Arguments

sce

SingleCellExperiment object

target

Name of target variable for prediction

group

Grouping variable for cross-validation, e.g., patient

assay_type

A string specifying the assay

Value

data.frame


Aggregate predicted leave-one-out probabilities over meta variables over a list of SingleCellExperiment objects

Description

Aggregate predicted leave-one-out probabilities over meta variables over a list of SingleCellExperiment objects

Usage

calculateStats(sce, target, group, assay_type = "tfmfeatures")

Arguments

sce

A SingleCellExperiment object

target

Name of target variable for prediction

group

Grouping variable for cross-validation, e.g., patient

assay_type

A string specifying the assay

Value

data.frame

Examples

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

Description

Internal function to compute y_hat on a subset of the features

Usage

compute_y_hat(
  feature_name,
  sce_feature,
  starts,
  target,
  group,
  interest_level,
  reference_level,
  weights,
  n_threads,
  assay_type
)

Arguments

feature_name

String with feature name

sce_feature

SingleCellExperiment

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

Value

tibble data frame


Simulate CellProfiler data and write to a temporary file

Description

Simulate CellProfiler data and write to a temporary file

Usage

generate_data()

Value

path to csv file

Examples

set.seed(23)
generate_data()

Load cell painting data from file and convert to a SingleCellExperiment

Description

Load cell painting data from file and convert to a SingleCellExperiment

Usage

loadData(cell_file)

Arguments

cell_file

path to csv file from CellProfiler, e.g., MyExpt_Cells.csv

Value

SingleCellExperiment object

Examples

set.seed(23)
cell_file <- generate_data()
loadData(cell_file)

Plot AUC comparison

Description

Plot AUC comparison

Usage

plotAUC(sce, target, group, assay_type = "tfmfeatures")

Arguments

sce

A SingleCellExperiment object

target

Name of target variable for prediction

group

Grouping variable for cross-validation, e.g., patient

assay_type

A string specifying the assay

Value

ggplot2 object

Examples

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

Description

Plot number of cells per image

Usage

plotCellsPerImage(sce, bins = 100)

Arguments

sce

SingleCellExperiment object

bins

Number of histogram bins

Value

ggplot2 object

Examples

set.seed(23)
cell_file <- generate_data()
sce <- loadData(cell_file)
plotCellsPerImage(sce)

Plot predicted leave-one-out probabilities

Description

Plot predicted leave-one-out probabilities

Usage

plotLOO(sce, target, group, assay_type = "tfmfeatures")

Arguments

sce

SingleCellExperiment object

target

Name of target variable for prediction

group

Grouping variable for cross-validation, e.g., patient

assay_type

A string specifying the assay

Value

ggplot2 object

Examples

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

Description

Plot number of cells per image

Usage

plotPCACor(
  sce,
  filter_by = 1,
  top = 20,
  pcs = seq(5),
  assay_type = "tfmfeatures"
)

Arguments

sce

SingleCellExperiment object

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

Value

ggplot2 object

Examples

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

Description

Plot ROC curves

Usage

plotROC(sce, target, group, assay_type = "tfmfeatures")

Arguments

sce

SingleCellExperiment object

target

Name of target variable for prediction

group

Grouping variable for cross-validation, e.g., patient

assay_type

A string specifying the assay

Value

ggplot2 object

Examples

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

Description

Predict target from features

Usage

predictLOO(
  sce,
  target,
  group,
  interest_level,
  reference_level,
  types = NULL,
  channels = NULL,
  weights = NULL,
  n_threads = 1,
  assay_type = "tfmfeatures"
)

Arguments

sce

SingleCellExperiment object

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

Value

tibble data frame

Examples

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

Description

Filter low variance features

Usage

removeLowVariance(sce, threshold = 0, robust = FALSE)

Arguments

sce

SingleCellExperiment object

threshold

Keep features that have larger variance than this threshold

robust

If true use median absolute deviation, otherwise use variance

Value

SingleCellExperiment object

Examples

set.seed(23)
cell_file <- generate_data()
sce <- loadData(cell_file)
sce <- removeLowVariance(sce)

Remove cells with missing features

Description

Remove cells with missing features

Usage

removeNAs(sce)

Arguments

sce

SingleCellExperiment object

Value

SingleCellExperiment object

Examples

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

Description

Remove cells if not enough or too many in one image

Usage

removeOutliers(sce, min, max)

Arguments

sce

SingleCellExperiment object

min

Remove cells below that number

max

Remove cells above that number

Value

SingleCellExperiment object

Examples

set.seed(23)
cell_file <- generate_data()
sce <- loadData(cell_file)
sce <- removeOutliers(sce, min = 0, max = 300)

Remove zero-inflated features

Description

Remove zero-inflated features

Usage

removeZeroInflation(sce, proportion = 0.2)

Arguments

sce

SingleCellExperiment object

proportion

Remove features exceeding this zero-inflation proportion

Value

SingleCellExperiment object

Examples

set.seed(23)
cell_file <- generate_data()
sce <- loadData(cell_file)
sce <- removeZeroInflation(sce)

Filter low variance features

Description

Filter low variance features

Usage

transformLogScale(sce, robust = FALSE)

Arguments

sce

SingleCellExperiment object

robust

If true robust z-score, otherwise standard z-score

Value

SingleCellExperiment object

Examples

set.seed(23)
cell_file <- generate_data()
sce <- loadData(cell_file)
sce <- transformLogScale(sce)

Plot predicted leave-one-out probabilities

Description

Plot predicted leave-one-out probabilities

Usage

volcanoPlot(
  sce,
  target,
  group,
  p_cutoff = NULL,
  fc_cutoff = 1,
  assay_type = "tfmfeatures"
)

Arguments

sce

A SingleCellExperiment object

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

Value

ggplot2 object

Examples

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
)