lfcShrink: Error when using numerical contrast vector
1
0
Entering edit mode
@amalthomas111-13189
Last seen 2.6 years ago
United States

Hi,

I am trying to visualize the genes using DESeq2:: plotMA after LFC shrinkage. Since my design is bit complicated, I am using numerical vector for my contrast.

I obtained the result table using:

res = results(dds, alpha=0.05, contrast = c(0,0,0,0,0,-1/7,-1/7,-1/7,1/3,0,-1/7,-1/7,1/3,0,-1/7,1/3,0,-1/7))

This works fine.  Now I want to visualize the result for the same contrast using MA plot after lfcShrink.

resLFC = lfcShrink(dds,contrast = c(0,0,0,0,0,-1/7,-1/7,-1/7,1/3,0,-1/7,-1/7,1/3,0,-1/7,1/3,0,-1/7))

After running for  ~10mins, I get this error:

Error in checkContrast(contrast, resNames) : numeric contrast vector should have one element for every element of 'resultsNames(object)'

I checked my numerical vector. For every term in the resultsNames(dds), I have the correct weights. 

data.frame(element=resultsNames(dds),weight=c(0,0,0,0,0,-1/7,-1/7,-1/7,1/3,0,-1/7,-1/7,1/3,0,-1/7,1/3,0,-1/7))

https://imgur.com/a/29lw0

Using DESeq2_1.18.1

Thanks, 

deseq2 • 1.6k views
ADD COMMENT
1
Entering edit mode
@mikelove
Last seen 14 hours ago
United States

hi Amal,

Thanks for this report. It's tricky to use a numeric or list-style contrast here. Using 'contrast' with type="normal" makes use of expanded model matrices. And so the numeric or list need to reference coefficients from an expanded model matrix, but you don't see those when you run resultsNames(dds). It's probably easier for you to just use DESeq() with betaPrior=TRUE followed by results(). I've added this note to the man page for ?lfcShrink now. This option (betaPrior=TRUE) will always be supported in DESeq2 for backwards compatibility, though we have now designed a better shrinkage estimator, and are slowly transitioning away from type="normal".

> dds <- DESeq(dds, betaPrior=TRUE, quiet=TRUE)
> resultsNames(dds)
[1] "Intercept"  "conditionA" "conditionB"
> res <- results(dds, contrast=c(0,-1,1))

Also, as you noted above, lfcShrink() should be giving an error earlier, so I've fixed this now in the development branch. Also, you don't have access to see the relevant resultsNames vector, because it is built inside of lfcShrink(), where DESeq() and results() are called. My fix for lfcShrink() in the devel branch is that I've added checks on 'contrast' ahead of running DESeq(), and also I now print out the vector of resultsNames for the expanded model matrix, so the user can make sure they are providing the correct contrast. 

In the below example, the error is coming before DESeq() is called internally to lfcShrink().

> dds <- makeExampleDESeqDataSet()
> dds <- DESeq(dds, quiet=TRUE)
> res <- results(dds)
> lfcShrink(dds, contrast=c(0,1), res=res, type="normal")
resultsNames from the expanded model matrix to be referenced by 'contrast':
'Intercept', 'conditionA', 'conditionB'
Error in checkContrast(contrast, resNames) : 
  numeric contrast vector should have one element for every element of 'resultsNames(object)'
Calls: lfcShrink -> checkContrast
> res <- lfcShrink(dds, contrast=c(0,-1,1), res=res, type="normal")
resultsNames from the expanded model matrix to be referenced by 'contrast':
'Intercept', 'conditionA', 'conditionB'
ADD COMMENT
0
Entering edit mode

Thank you, Michael. Greatly appreciate the efforts you put to respond as soon as possible :-)

ADD REPLY

Login before adding your answer.

Traffic: 779 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