LieberInstitute / jaffelab

R package with commonly used functions by the Jaffe lab
http://lieberinstitute.github.io/jaffelab
7 stars 3 forks source link

merge_rse_metrics --> add ERCCsumLogErr column to be merged #3

Closed andrewejaffe closed 6 months ago

andrewejaffe commented 5 years ago

check if the column is present (since not all experiments have this) but if its present, include in the merging

lcolladotor commented 6 months ago

Looks like we had this issue open since 2019. Here's an approximate solution as discussed in the qsvaR project https://jhu-genomics.slack.com/archives/C018ZDB8QLU/p1710454545453089

suppressPackageStartupMessages(library("IRanges"))

## Read in the ERCC expected concentration
spikeIns <- read.delim("https://raw.githubusercontent.com/LieberInstitute/SPEAQeasy/master/Annotation/ERCC/ercc_actual_conc.txt",
        as.is = TRUE, row.names = 2
    )

## Identify the number of ERCC sequences
n_erccs <- nrow(spikeIns)

## Calculate the ERCC expected concentration
ercc_expected_conc <- sum(log2(10 * spikeIns[, "concentration.in.Mix.1..attomoles.ul."] + 1))

## Then compute the approximate result starting from a NumericList input
sapply(rse$ERCCsumLogErr, function(sumlogerr) {
    log2(mean( (2^(sumlogerr + ercc_expected_conc))^(1/n_erccs))^n_erccs) - ercc_expected_conc
})