Hi everyone. I have a problem with DESeq2 counts in r.
when I use this code:
raw_readcount <- fread("raw read counts.txt", header = TRUE, sep = "\t")
design <- fread("Design.txt", header = TRUE, sep = "\t")
define effects the model should account for (animals, patients, batch effects etc.)
model_factors <- c("Patient")
define factors to test for DEG to use with model_factors
test_factors <- c("Timepoint")
run normalization and DEG for every combination of modelling and testing factors
dds_list <- list(test_factors)
res_list <- list(model_factors)
for (i in test_factors) {
dds_list[[paste("dds_", paste(model_factors, sep = "+"), "_", i, sep = "")]] <- DESeqDataSetFromMatrix(data.frame(raw_readcount, row.names = 1),design,as.formula(paste("~", paste(model_factors, sep = "+"), "+", i)))
dds_list[[paste("dds_", paste(model_factors, sep = "+"), "_", i, sep = "")]] <- DESeq(dds_list[[paste("dds_", paste(model_factors, sep = "+"), "_", i, sep = "")]], parallel = T)
DEG_levels <- combn(sort(unique(get(i,design))),2)
for (j in 1:ncol(DEG_levels)) {
res_list[[paste("res", paste(model_factors, sep = "+"), i, DEG_levels[1,j], DEG_levels[2,j], sep = "_")]] <- results(dds_list[[paste("dds_", paste(model_factors, sep = "+"), "_", i, sep = "")]], contrast=c(i, DEG_levels[1,j], DEG_levels[2,j]), parallel = T)
res_list[[paste("res", paste(model_factors, sep = "+"), i, DEG_levels[1,j], DEG_levels[2,j], sep = "_")]] <- res_list[[paste("res", paste(model_factors, sep = "+"), i, DEG_levels[1,j], DEG_levels[2,j], sep = "_")]][order(res_list[[paste("res", paste(model_factors, sep = "+"), i, DEG_levels[1,j], DEG_levels[2,j], sep = "_")]]$padj), ]
}
}
generate normalized count lists
normalized_reads_list <- list(dds_list)
mean_normalized_reads_list <- list(dds_list)
normalized_reads_list <- list(res_list)
mean_normalized_reads_list <- list(res_list)
for (i in names(dds_list)) {
normalized_reads_list[[sub("dds", "normalized_reads", i)]] <- as.data.frame(counts(dds_list[[i]], normalized=TRUE, replaced = T))
normalized_reads_list[[sub("dds", "normalized_reads", i)]]$Geneid <- row.names(normalized_reads_list[[sub("dds", "normalized_reads", i)]])
setcolorder(normalized_reads_list[[sub("dds", "normalized_reads", i)]], neworder = "Geneid")
mm <- match(names(normalized_reads_list[[sub("dds", "normalized_reads", i)]][-(1)]), design$Sample)
mean_reads <- normalized_reads_list[[sub("dds", "normalized_reads", i)]][,-c(1)]
names(mean_reads)[!is.na(mm)] <- as.character(design[ , get(sub(paste(paste(model_factors, sep = "+"),"_", sep = ""), "", sub("dds_", "", i)))][na.omit(mm)])
mean_normalized_reads_list[[sub("dds", "mean_normalized_reads", i)]] <- data.frame("Geneid" = rownames(mean_reads),lapply(split(as.list(mean_reads),f = colnames(mean_reads)),function(x) Reduce(`+`,x) / length(x)))
}
I'm getting this error:
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'as.data.frame': unable to find an inherited method for function ‘counts’ for signature ‘"NULL"’
These's my DATA (all cells separate with tab):
Design File:
raw read counts File:
There is this
10101
botton to highlight code, please use it. This wall of code and data is barely readable.Thanks a lot.