This is a test version of Biostars. For the public version, visit https://www.biostars.org.
DESeq2 dds Creation

Hello,

I am trying to generate a dds out of a count matrix file. I haven successfully imported the count matrix for "countData" as well as the metadata for "colData" but when I run "DESeqDataFromMatrix" I receive the error

Error in SummarizedExperiment(assays = SimpleList(counts = countData), : the rownames and colnames of the supplied assay(s) must be NULL or identical to those of the SummarizedExperiment object (or derivative) to construct

Below are the code lines I am running to get to this point, any help would be appreciated to generate a dds so I can run DESeq2.

raw_counts <- read.csv("raw_counts.csv", header = TRUE, row.names = 1)
countdata <- as.matrix(raw_counts)
coldata <- read.csv("metadata.csv", header = T, row.names = 1)
dds <- DESeqDataSetFromMatrix(countData = countdata,
                          colData = coldata,
                          design = ~ sample)

Thank you.

deseq2

1 answer

object 'countData' not found

It must be countdata, with a lowercase d as in the 2nd line of code.

Yes, thank you I caught that right before seeing this! I get a new error when I correct that which is:

Error in SummarizedExperiment(assays = SimpleList(counts = countData), : the rownames and colnames of the supplied assay(s) must be NULL or identical to those of the SummarizedExperiment object (or derivative) to construct

Check that all(rownames(coldata) %in% colnames(countdata)). If it returns FALSE, your colData rownames don't match the column names for the counts, so the samples can't be properly associated with the sample-specific metadata.

Correcting that should solve the error.

Great, thank you. It seems they are not aligned. What code would align the two?

In the simplest case you make an intersect, to get the samples that are in both countdata and coldata and then sort them. Something like:

#/ for example (untested)
i <- intersect(colnames(countdata), rownames(coldata))`
countsdata2 <- countdata[,i]
coldata2 <- coldata[i,]

Log in to answer this question.