Skip to contents

This function calculates the mean and standard deviation of the expression of each gene in an expression matrix, grouped by the conditions supplied.

Usage

calculate_condition_mean_sd_per_gene(expression.matrix, condition)

Arguments

expression.matrix

the expression matrix; rows correspond to genes and columns correspond to samples; usually preprocessed by preprocessExpressionMatrix; a list (of the same length as modality) can be provided if #' length(modality) > 1

condition

the condition to group the columns of the expression matrix by; must be a factor of the same length as ncol(expression.matrix)

Value

A tibble in long format, with the mean and standard deviation of each gene in each condition. The standard deviation is increased to the minimum value in the expression matrix (the noise threshold) if it is lower, in order to avoid sensitivity to small changes.

Examples

expression.matrix.preproc <- as.matrix(read.csv(
  system.file("extdata", "expression_matrix_preprocessed.csv", package = "bulkAnalyseR"), 
  row.names = 1
))[1:500,]

condition <- factor(rep(c("0h", "12h", "36h"), each = 2))
tbl <- calculate_condition_mean_sd_per_gene(expression.matrix.preproc[1:10, ], condition)
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
tbl
#> # A tibble: 30 x 4
#>    gene               condition    mean    sd
#>    <chr>              <fct>       <dbl> <dbl>
#>  1 ENSMUSG00000025902 0h          106.   45.7
#>  2 ENSMUSG00000025902 12h          60.8  45.7
#>  3 ENSMUSG00000025902 36h          60.2  45.7
#>  4 ENSMUSG00000098104 0h           95.8  45.7
#>  5 ENSMUSG00000098104 12h          86.1  45.7
#>  6 ENSMUSG00000098104 36h          78    45.7
#>  7 ENSMUSG00000103922 0h          281.   45.7
#>  8 ENSMUSG00000103922 12h         376.   48.4
#>  9 ENSMUSG00000103922 36h         315.   45.7
#> 10 ENSMUSG00000033845 0h        10868.  933. 
#> # ... with 20 more rows