Normalised counts from RUVg in RUVSeq
4
0
Entering edit mode
Pauly Lin ▴ 160
@pauly-lin-7537
Last seen 9.2 years ago
University of New South Wales, Australia

Hi, 

I'm using the function RUVg in the RUVSeq package to analyse my RNA-seq data. The output of RUVg consists of the factors of unwanted variation W and the normalised counts N. Could someone please tell me how the normalised counts N are calculated? See the formula below.

log E[Y |W, X, O] = W α + Xβ + O. 

Are the normalised counts simply log(Y)-Wα-O? If so, how can I get α from the output of RUVg? Also, log(Y)-Wα-O wouldn't consist of integers, so why does the normalised counts matrix N produced by RUVg consist of counts?

Thanks!

Paul

RUVg ruvseq rnaseq • 8.2k views
ADD COMMENT
1
Entering edit mode
davide risso ▴ 980
@davide-risso-5075
Last seen 9 months ago
University of Padova

Hi Paul,

I'm glad you figured it out yourself. I'll just post an answer anyway in case somebody else has a similar issue.

The normalized counts are indeed simply the residuals from ordinary least squares regression of logY on W (with the offset if needed)􏰂. The output from RUV is actually exponentiated (and optionally rounded) to be interpretable as "normalized counts". Please, note that these are intended just for visualization/exploration, as the RUV model has been tested only on supervised problems, and works better when W is inserted in the model with the original counts (rather than modeling the normalized counts).

Similarly, the alpha estimated from the first step of RUV shouldn't probably be used directly (and hence is not returned), but rather alpha and beta will be (re-)estimated by the full model on W and X. If you're using edgeR, you should find the estimated parameters in the output of glmFit (coefficients).

 

ADD COMMENT
0
Entering edit mode

Hello I was wondering if I should use ruv-corrected counts and ruv lib sizes to create a DGE object that can be used later for DE analysis using limma voom?

ADD REPLY
1
Entering edit mode

Our recommended approach is to add the estimated factors of RUV in the design matrix of the DGE object. We illustrate this with edgeR and DESeq2 in the vignette and it will be similar for limma-voom, e.g., use the library-size normalized log-counts (the same input you gave to RUV) and include W in the design matrix.

ADD REPLY
0
Entering edit mode

I am trying to add factors of unwanted variation "W" to the design matrix but I am confused because the design matrix will be used to make contrasts to fit a linear model and perform empirical Bayes moderation and it gives me this error below.

      design = model.matrix(~0 + dge_post$samples$Stage
                         +dge_post$samples$Age
                       +dge_post$samples$Sex
                      +dge_post$samples$Sample.source
                      +dge_post$samples$Sample.ID
                        + dge_post$samples$Sample.ID
                        + dge_post$samples$lib.size
                        )

            colnames(design)[1] ="Control"
            colnames(design)[2] ="Stage1"
            colnames(design)[3] ="Stage2"
            colnames(design)[4] ="Stage3"
            colnames(design)[5] ="Stage4"

            v=voomWithQualityWeights(dge_post, plot=TRUE)
            levels_for_contrasts <- colnames(design)[1:5]

            vfit <- lmFit(v, design)

            contrast.matrix <- makeContrasts(Stage1vsControl=Stage1-Control,
                                 Stage2vsControl=Stage2-Control,
                                 Stage3vsControl=Stage3-Control,
                                 Stage4vsControl=Stage4-Control, 
                                 levels = levels_for_contrasts)

          vfit <- contrasts.fit(vfit, contrasts=contrast.matrix)

> vfit <- contrasts.fit(vfit, contrasts=contrast.matrix)
Error in contrasts.fit(vfit, contrasts = contrast.matrix) : 
  object 'vfit' not found
fit <- lmFit(v, design)
Coefficients not estimable: dge_post$samples$Sample
ADD REPLY
2
Entering edit mode

First a pedantic note. It's easier and clearer to do this

design <- model.matrix(~ 0 + Stage + Age + Sex + Sample.source + Sample.ID, dge_post$samples)

Rather than how you did it.

Second, you have Sample.ID in your design matrix twice. It won't matter because model.matrix will drop one, but it makes me wonder if that is really what you did. I say that because your error says you cannot estimate dge_post$samples$Sample, which shouldn't be a coefficient if you used the code you have supplied. An alternative is that you cropped off part of the error message, but either way it's not possible to help given the information you have provided.

Third, in this context you should use voomLmFit instead

fit <- voomLmFit(dge_post, design, sample.weights = TRUE)

And if you don't have complete pairing (which I suspect you don't), you probably won't be able to fit Sample.ID as a fixed effect, in which case you should fit a GLS.

design <- model.matrix(~ 0 + Stage + Age + Sex + Sample.source, dge_post$samples) ## NO Sample.ID here
fit <- voomLmFit(dge_post, design, dge_post$samples$Sample.ID, sample.weights = TRUE)
fit2 <- eBayes(contrasts.fit(fit, contrast.matrix))

But again, I am just guessing because your error doesn't make sense given how you constructed the design matrix (there's no dge_post$samples$Sample used anywhere).

ADD REPLY
0
Entering edit mode

Can I use ruv normalized counts in logistic regression? if not, then how to remove the unwanted variation from the gene expression matrix after estimating W?

ADD REPLY
0
Entering edit mode
Pauly Lin ▴ 160
@pauly-lin-7537
Last seen 9.2 years ago
University of New South Wales, Australia

I have figured this out myself, so no need to answer this question any more. 

Cheers

Paul

ADD COMMENT
0
Entering edit mode
cbcb • 0
@cbcb-11126
Last seen 8.4 years ago

Hello,

How to apply RUVg normalization on my FPKM or counts table followed by export/write the normalized data frame to a directory?

Many thanks for your kind help in advance.

Chris

 

 

ADD COMMENT
0
Entering edit mode

Hi Chris,

please, use the "Add Answer" field only to answer the original posted question. If you have a new question, please open a new thread. 

In this particular case, it looks like the best place for you to start is by reading the RUVg vignette, available here:

https://www.bioconductor.org/packages/release/bioc/vignettes/RUVSeq/inst/doc/RUVSeq.pdf

ADD REPLY
0
Entering edit mode

Hi David,

Many thanks for your quick reply.

I did start with the RUVSeq vignette, but i can't find how to export the normalized counts? I have got a kinetics data and I dont know how to apply DESeq on such a data. Hence, I would like to export the RUVg normalized data frame.

 

Thanks,

 

Chris

ADD REPLY
0
Entering edit mode

The way you extract normalized counts depends on what object you're working on. If you're starting with a matrix, RUVg will return a list with two elements, one of which is the matrix of normalized counts.

If you're working with a SeqExpressionSet object, then you can use the normCounts() method to extract the normalized data. This is all documented in the RUVg manual page, available with:

?RUVSeq::RUVg

Have a look also at

?EDASeq::normCounts​
ADD REPLY
0
Entering edit mode
cbcb • 0
@cbcb-11126
Last seen 8.4 years ago

Could you please comment on the below commands? is it right way to get the RUVg normalized data?

thanks,

 

my_data=read.table(my_data_file, sep="\t", header=TRUE)

ercc_rows <- grep("^ERCC", rownames(my_data))
my_data_ruv_object_k1 <- RUVg(x = as.matrix(my_data), cIdx = ercc_rows, k = 1)
my_data_ruv_k1 <- my_data_ruv_object_k1$normalizedCounts

 

ADD COMMENT
0
Entering edit mode

That's correct. 

ADD REPLY
0
Entering edit mode

> tail(my_data)
             A_count   B_count     D_count    C_count
ERCC-00163   38.02860   42.57420   30.858200    29.8872
ERCC-00164    0.00000    1.12037    0.907595     0.0000
ERCC-00165  184.29200  211.75100  155.199000   174.3420
ERCC-00168    2.92528    1.12037    0.907595     0.0000
ERCC-00170   48.75460   62.74100   66.254400    78.7031
ERCC-00171 8049.39000 6976.57000 5932.040000  6338.0900

 

> tail(my_data_ruv_k1 )
           A_count    B_count    D_count     C_count
ERCC-00163 3.65079862  3.7640702  3.5198576  3.3956702
ERCC-00164 0.08228729  0.8149703  0.2887788  0.2113975
ERCC-00165 5.19581388  5.3400049  5.1644678  5.0996380
ERCC-00168 1.39912058  0.7759935  0.5083635  0.0813939
ERCC-00170 3.90363981  4.1521606  4.2235097  4.3694117
ERCC-00171 8.97126617  8.8333496  8.7846650  8.6974335

 

Why do my 0 read counts get assigned values after RUVg normalization?

is it expected to happen?

Many thanks
 

ADD REPLY
0
Entering edit mode

Yes. It can happen since the "normalized data" are simply the residuals of a linear model, and there is no constraint in the model to force zero to stay zero. Note that in practice this will all be close to 0.

Also, keep in mind that the normalzed value are in the log(x+1) scale.

ADD REPLY
0
Entering edit mode

many thanks

ADD REPLY

Login before adding your answer.

Traffic: 469 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6