Skip to contents

This method performs a Z-score transformation on a protein-wise (row-wise) basis. For each protein, it calculates the mean and standard deviation of its abundance across all samples and then scales the values accordingly.

This is a standard transformation for visualizing expression patterns in a heatmap, as it highlights the relative change of each protein across samples, independent of its absolute abundance.

Usage

z_score(object)

# S4 method for class 'SummarizedExperiment'
z_score(object)

Arguments

object

A SummarizedExperiment object

Value

object A SummarizedExperiment object where the abundance values in the assay slot have been replaced by their row-wise Z-scores.

See also

Examples

# Create sample data with proteins as rows and samples as columns
df <- data.frame(
  Protein = c("Protein1", "Protein2", "Protein3"),
  SampleA = c(100, 250, 50),
  SampleB = c(120, 200, 100),
  SampleC = c(110, 225, 75)
)

sample_info <- data.frame(
  SampleID = c("SampleA", "SampleB", "SampleC"),
  group = c("Control", "Treatment", "Control")
)

se <- create_se(df, sample_metadata = sample_info)
#> `intensity_cols` not provided. Detecting numeric columns as intensity data.

# Check the means of each protein (row) before scaling
rowMeans(SummarizedExperiment::assay(se))
#> [1] 110 225  75

# Apply the scaling method
scaled_se <- z_score(se)

# The new data has row means near zero and row standard deviations of one
print(SummarizedExperiment::assay(scaled_se))
#>      SampleA SampleB SampleC
#> [1,]      -1       1       0
#> [2,]       1      -1       0
#> [3,]      -1       1       0
#> attr(,"scaled:center")
#> [1] 110 225  75
#> attr(,"scaled:scale")
#> [1] 10 25 25
cat("Row means after scaling:\n")
#> Row means after scaling:
print(rowMeans(SummarizedExperiment::assay(scaled_se)))
#> [1] 0 0 0
cat("\nRow standard deviations after scaling:\n")
#> 
#> Row standard deviations after scaling:
print(apply(SummarizedExperiment::assay(scaled_se), 1, sd))
#> [1] 1 1 1