如何克服 shrink , in deseq ?
How to overcome shrink , in deseq?
目前正在尝试两组间的差异表达。此代码在 6 个月前有效,但现在我得到:
deseq2 库
> converting counts to integer mode estimating size factors estimating
> dispersions gene-wise dispersion estimates mean-dispersion
> relationship final dispersion estimates fitting model and testing
> -- replacing outliers and refitting for 7129 genes
> -- DESeq argument 'minReplicatesForReplace' = 7
> -- original counts are preserved in counts(dds) estimating dispersions fitting model and testing
> **Error in lfcShrink(dds = this.dds, contrast = c("condition", G1.desc, : type='apeglm' shrinkage only for use with 'coef' In
> addition: Warning message: In DESeqDataSet(se, design = design,
> ignoreRank) : some variables in design formula are characters,
> converting to factors**
this.dds <- DESeqDataSetFromMatrix(countData = this.dat,
colData = this.coldata,
design = ~ condition)
this.dds$condition <- factor(this.dds$condition, levels = c(G1.desc,G2.desc))
if (! exists("Dseq_results")) {
Dseq_results <- DESeq(this.dds)
}
this.dds <- Dseq_results
res <- results(this.dds,
name=sprintf("condition_%s_vs_%s",G1.desc,G2.desc),contrast = c('condition',G1.desc,G2.desc)
)
tmp1 <<- this.dds
print(tmp1)
res1 <- lfcShrink(dds=this.dds,contrast = c('condition',G1.desc,G2.desc), res=res)
res1.nice=cbind(rownames(HTseq.counts),res1$baseMean,res1$log2FoldChange,res1$lfcSE,res1$stat,res1$pvalue,res1$padj)
colnames(res1.nice)<-c('Gene','baseMean','log2FoldChange','lfcSE','stat','pvalue','padj')
return(res1.nice)
g1,g2 是组,desc - 描述,this.dds - 保存 htseq 计数的数据。
我尝试将类型中的类型从“apeglm”更改为 'ashr',但出现了不同的错误。没有打印任何内容。
举个例子,我真的不确定你对 G1.desc
有什么要求,但可以说:
G1.desc = "A"
G2.desc = "B"
this.dat = matrix(rnbinom(3000,mu=50,size=0.1),ncol=6)
colnames(this.dat) = paste0("s",1:6)
this.coldata = data.frame(condition = rep(c("A","B"),each=3))
在你把它放入deseq对象之前的因素,在这里你已经可以决定对比度了:
this.coldata$condition = factor(this.coldata$condition,
levels=c(G1.desc,G2.desc))
运行 DESeq:
this.dds <- DESeqDataSetFromMatrix(countData = this.dat,
colData = this.coldata,
design = ~ condition)
this.dds <- DESeq(this.dds)
res <- results(this.dds,
name=sprintf("condition_%s_vs_%s",G1.desc,G2.desc),
contrast = c('condition',G1.desc,G2.desc)
)
是的,我在“apeglm”上遇到了与您相同的错误:
l2fc = sapply(c("normal","ashr","apeglm"),function(i){
lfcShrink(dds=this.dds,
contrast = c('condition',G1.desc,G2.desc), res=res,type=i)$log2FoldChange
})
Error in lfcShrink(dds = this.dds, contrast = c("condition", G1.desc, :
type='apeglm' shrinkage only for use with 'coef'
如果你像我上面那样设置因素,对比度总是G2.desc vs G1.desc,你可以看到:
resultsNames(this.dds)
[1] "Intercept" "condition_B_vs_A"
所以你只是不提供 res =
参数:
l2fc = sapply(c("normal","ashr","apeglm"),function(i){
lfcShrink(dds=this.dds,coef=2,type=i)$log2FoldChange
})
head(l2fc)
normal ashr apeglm
[1,] -0.2313623 -0.1739082 -0.02573008
[2,] -1.0543602 -0.8159166 -0.11381314
[3,] 2.2493688 1.8142392 0.24608219
[4,] 3.5059792 3.0354023 0.22795819
[5,] 2.8617158 2.3939858 0.32407906
[6,] -0.2236092 -0.1710536 -0.02053698
目前正在尝试两组间的差异表达。此代码在 6 个月前有效,但现在我得到: deseq2 库
> converting counts to integer mode estimating size factors estimating
> dispersions gene-wise dispersion estimates mean-dispersion
> relationship final dispersion estimates fitting model and testing
> -- replacing outliers and refitting for 7129 genes
> -- DESeq argument 'minReplicatesForReplace' = 7
> -- original counts are preserved in counts(dds) estimating dispersions fitting model and testing
> **Error in lfcShrink(dds = this.dds, contrast = c("condition", G1.desc, : type='apeglm' shrinkage only for use with 'coef' In
> addition: Warning message: In DESeqDataSet(se, design = design,
> ignoreRank) : some variables in design formula are characters,
> converting to factors**
this.dds <- DESeqDataSetFromMatrix(countData = this.dat,
colData = this.coldata,
design = ~ condition)
this.dds$condition <- factor(this.dds$condition, levels = c(G1.desc,G2.desc))
if (! exists("Dseq_results")) {
Dseq_results <- DESeq(this.dds)
}
this.dds <- Dseq_results
res <- results(this.dds,
name=sprintf("condition_%s_vs_%s",G1.desc,G2.desc),contrast = c('condition',G1.desc,G2.desc)
)
tmp1 <<- this.dds
print(tmp1)
res1 <- lfcShrink(dds=this.dds,contrast = c('condition',G1.desc,G2.desc), res=res)
res1.nice=cbind(rownames(HTseq.counts),res1$baseMean,res1$log2FoldChange,res1$lfcSE,res1$stat,res1$pvalue,res1$padj)
colnames(res1.nice)<-c('Gene','baseMean','log2FoldChange','lfcSE','stat','pvalue','padj')
return(res1.nice)
g1,g2 是组,desc - 描述,this.dds - 保存 htseq 计数的数据。 我尝试将类型中的类型从“apeglm”更改为 'ashr',但出现了不同的错误。没有打印任何内容。
举个例子,我真的不确定你对 G1.desc
有什么要求,但可以说:
G1.desc = "A"
G2.desc = "B"
this.dat = matrix(rnbinom(3000,mu=50,size=0.1),ncol=6)
colnames(this.dat) = paste0("s",1:6)
this.coldata = data.frame(condition = rep(c("A","B"),each=3))
在你把它放入deseq对象之前的因素,在这里你已经可以决定对比度了:
this.coldata$condition = factor(this.coldata$condition,
levels=c(G1.desc,G2.desc))
运行 DESeq:
this.dds <- DESeqDataSetFromMatrix(countData = this.dat,
colData = this.coldata,
design = ~ condition)
this.dds <- DESeq(this.dds)
res <- results(this.dds,
name=sprintf("condition_%s_vs_%s",G1.desc,G2.desc),
contrast = c('condition',G1.desc,G2.desc)
)
是的,我在“apeglm”上遇到了与您相同的错误:
l2fc = sapply(c("normal","ashr","apeglm"),function(i){
lfcShrink(dds=this.dds,
contrast = c('condition',G1.desc,G2.desc), res=res,type=i)$log2FoldChange
})
Error in lfcShrink(dds = this.dds, contrast = c("condition", G1.desc, :
type='apeglm' shrinkage only for use with 'coef'
如果你像我上面那样设置因素,对比度总是G2.desc vs G1.desc,你可以看到:
resultsNames(this.dds)
[1] "Intercept" "condition_B_vs_A"
所以你只是不提供 res =
参数:
l2fc = sapply(c("normal","ashr","apeglm"),function(i){
lfcShrink(dds=this.dds,coef=2,type=i)$log2FoldChange
})
head(l2fc)
normal ashr apeglm
[1,] -0.2313623 -0.1739082 -0.02573008
[2,] -1.0543602 -0.8159166 -0.11381314
[3,] 2.2493688 1.8142392 0.24608219
[4,] 3.5059792 3.0354023 0.22795819
[5,] 2.8617158 2.3939858 0.32407906
[6,] -0.2236092 -0.1710536 -0.02053698