This is a test version of Biostars. For the public version, visit https://www.biostars.org.
DESeq2 error: ncol(countData) == nrow(colData) is not TRUE

I'm an undergrad student who is just getting to grips with bioinformatics/RNAseq and appear to have ran into a common novice error with DESeq2. This is the code I am trying to run:

 dds <- DESeqDataSetFromMatrix(countData = rna_counts,
+         colData = rna_design, design = ~ condition )

Error in DESeqDataSetFromMatrix(countData = rna_counts, colData = rna_design,  : 
  ncol(countData) == nrow(colData) is not TRUE

I understand completely why this is happening, but am just looking on guidance of how to fix it. This is what my count and metadata looks like:

> head(rna_counts)
        featureid s69 s70 s71  s75 s76 s77
1 ENSG00000000003   1   1   0    8   2   1
2 ENSG00000000005   0   0   0    0   0   0
3 ENSG00000000419 993 469 664 1172 491 685
4 ENSG00000000457 385 207 235  610 226 353
5 ENSG00000000460 849 436 522 1002 430 608
6 ENSG00000000938  26   6  12   75  43  44

> rna_design
  sample.id condition
1       s69   control
2       s70   control
3       s71   control
4       s75   treated
5       s76   treated
6       s77   treated

How should I make these dimensions compatible?

rna-seq r deseq2

1 answer

Hey,

The problem is that the first column in your counts file relates to Ensembl gene IDs - these need to be set as rownames.

You just need to do this (prior to running any DESeq2 command)

head(rna_counts)
rownames(rna_counts) <- rna_counts[,1]
rna_counts <- rna_counts[,-1]
head(rna_counts)

all(colnames(rna_counts) == rna_design$sample.id)

If the final command in my code does not return TRUE, then there are still issues.

In light of this, you should also verify the encoding of your data via:

str(rna_counts)

Kevin

Thanks a lot Kevin, that was exactly what I was looking for. Have a nice day!

Log in to answer this question.