R语言 DESeq包报错Error in newCountDataSet(countTable, conds) : 不是所有的length(conditions) == ncol(countData)

问题遇到的现象和发生背景

R语言 DESeq包报错Error in newCountDataSet(countTable, conds) : 不是所有的length(conditions) == ncol(countData)

用代码块功能插入代码,请勿粘贴截图

rm(list = ls())
proj = "TCGA-UCEC"
if(F){
download.file(url = paste0("https://gdc.xenahubs.net/download/%22,proj, ".htseq_counts.tsv.gz"),destfile = paste0(proj,".htseq_counts.tsv.gz"))
download.file(url = paste0("https://gdc.xenahubs.net/download/%22,proj, ".GDC_phenotype.tsv.gz"),destfile = paste0(proj,".GDC_phenotype.tsv.gz"))
download.file(url = paste0("https://gdc.xenahubs.net/download/%22,proj, ".survival.tsv"),destfile = paste0(proj,".survival.tsv"))
}
clinical = read.delim(paste0(proj,".GDC_phenotype.tsv.gz"),fill = T,header = T,sep = "\t")
surv = read.delim(paste0(proj,".survival.tsv"),header = T)
clinical[1:4,1:4]

head(surv)

dat = read.table(paste0(proj,".htseq_counts.tsv.gz"),check.names = F,row.names = 1,header = T)
#逆转log
dat = as.matrix(2^dat - 1)
dat[1:4,1:4]

dat[97,9]

as.character(dat[97,9])

用apply转换为整数矩阵

exp = apply(dat, 2, as.integer)
exp[1:4,1:4] #行名消失

rownames(exp) = rownames(dat)
exp[1:4,1:4]

library(stringr)

行名ID转换:

head(rownames(exp))

library(AnnoProbe)
annoGene(rownames(exp),ID_type = "ENSEMBL") # 转换不了

rownames(exp) = str_split(rownames(exp),"\.",simplify = T)[,1];head(rownames(exp))

re = annoGene(rownames(exp),ID_type = "ENSEMBL");head(re)

library(tinyarray)
exp = trans_array(exp,ids = re,from = "ENSEMBL",to = "SYMBOL")
exp[1:4,1:4]

library(BiocManager)

library(DESeq2)

class(exp)
nrow(exp)
exp = exp[apply(exp, 1, function(x) sum(x > 0) > 0.5*ncol(exp)), ]
nrow(exp)

exp = exp[!duplicated(exp$symbol),]

pasillaCountTable <- data.frame(exp, header=TRUE)
head( pasillaCountTable )
con=ifelse(as.numeric(str_sub(colnames(pasillaCountTable),14,15)) < 10,'tumor','normal')
view(con)
pasillaDesign <- data.frame(
row.names = colnames( pasillaCountTable ),
condition = con,
libType = c(rep("paired-end",times=584) ))
pasillaDesign <-pasillaDesign[-584,]
pasillaDesign

pairedSamples <- pasillaDesign$libType == "paired-end"
countTable <- pasillaCountTable[ , pairedSamples ]
conds <- factor( c(pasillaDesign$condition ), levels = c("normal","tumor"))
conds
head(countTable)
view(condition)
view(countTable)
conditions(conds)

??newCountDataSet

library( DESeq )

options(repos = 'http://cran.rstudio.com/')

cds <- newCountDataSet(countTable, conds )
head( counts(cds) )


运行结果及报错内容

求解答

用DESeq包分析xena的tcga数据

生成cds数据时疯狂报错这个error

我的解答思路和尝试过的方法

不理解length这个报错,到底是什么需要相等