Question: DESeq2 Error: ncol(countData) == nrow(colData) is not TRUE
0
gravatar for jaqx008
5 months ago by
jaqx00850
jaqx00850 wrote:

Good day to you all. I have seen that many people ran into this error at some point while perfoming DESeq2 but I havent seen an answer that I am able to follow to get mine solved. I am mostly having problem relating the command to my data as I am new to DESeq2.

code

coldata <- read.csv("Conditions.txt")
cts <- as.matrix(read.csv("counts.txt", sep = '\t', row.names = NULL, header = FALSE))

Error

in DESeqDataSetFromMatrix(countData = cts, colData = coldata, design = ~Condition) : 
ncol(countData) == nrow(colData) is not TRUE

My count table looks like this with 4 replicates of sample A and four control of the same.

LociID:Length   Untreated1  Untreated2  Untreated3  Untreated4  Treated1    Treated2    Treated3    Treated4
f_V2_1:938  54  64  51  53  1649    1725    1739    1715
f_V2_1:953  238 252 252 260 49  49  63  52
f_V2_1:590  10  10  6   6   132 95  103 144
f_V2_1:1440 809 801 824 755 266 263 226 250

Am I doing something wrong?

rna-seq deseq2 R • 1.1k views
ADD COMMENTlink modified 5 months ago by i.sudbery5.0k • written 5 months ago by jaqx00850
1

Did you take a look at the DESeq2 vignette ?

Your Conditions.txt should look like this (screenshoot from this link above, Count matrix input part)

Capture

ADD REPLYlink modified 5 months ago • written 5 months ago by Bastien Hervé4.4k

Its a little bit confusing but what I understand is I should make condition like this and that is same as my coldata?

ADD REPLYlink written 5 months ago by jaqx00850
1

Generally you would add file names and condition (what ever you are trying to compare e.g. treated/untreated) as two minimum columns. If your count data is in the form of a matrix with sample file names as column headers.

ADD REPLYlink modified 5 months ago • written 5 months ago by genomax69k

What is the content of your colData?

ADD REPLYlink written 5 months ago by i.sudbery5.0k

All I gave what the count data. I dont have a coldata. I thought that command will write the conditions into the coldata or something. I dont know much about this sorry.

Condition
Untreated1
Untreated2
Untreated3
Untreated4
Treated1
Treated2
Treated3
Treated4
ADD REPLYlink written 5 months ago by jaqx00850

Since you are a beginner, I strongly recommend that you make coldata in Excel, not R, so you can see what you are doing. And when you see things are not working right, step one is to stop and go line by line through your script, and make sure you understand what every command does and why it is what it is.

ADD REPLYlink written 5 months ago by swbarnes26.0k
2
gravatar for i.sudbery
5 months ago by
i.sudbery5.0k
Sheffield, UK
i.sudbery5.0k wrote:

Explanation of the error

The error:

ncol(countData) == nrow(colData) is not TRUE

Is not too difficult to understand. The function ncol returns the number of columns in a matrix or dataframe and nrow does the same. In your countData (called cts in your case), each column is a sample. colData is a table that contains the information on each sample needed to decide which sample has which condition. Because DESeq requires information on every sample, it needs the number of columns in the count data to be the same as the number of rows in the colData. It is complaining that this is not the case, i.e. it is not true that the number of columns in count data is equal to the number of rows in the column data.

Fixing the error

Your command

coldata <- read.csv("Conditions.txt")

is trying to read from a file (Condition.txt) which sample has which condition (i.e treated or untreated). If you don't have a file called that, then this should be giving an error. Probably the simplest was to create this for your experiment you would be:

colData <- data.frame(condition = c("Untreated",  "Untre![enter image description here][1]ated", "Untreated", "Untreated", "Treated", "Treated", "Treated", "Treated")

However I recommend treating this file properly in excel because its good practice for when things get more complicated. Your excel file would look like:

conditions.txt

Save this file as a csv file called Conditions.txt and load it into R with:

coldata <- read.csv("Conditions.txt")

Either way, you can now create the DESeq object with:

dds <- DESeqDataSetFromMatrix(countData = cts, colData = coldata, design = ~Condition)
ADD COMMENTlink modified 5 months ago • written 5 months ago by i.sudbery5.0k

Ok Thanks and sorry for late response. I am about to try this out

ADD REPLYlink written 5 months ago by jaqx00850

This was helpful and I proceeded to plot my graph. Thanks for your suggestion and remaking my conditions file too. Thanks again :)

ADD REPLYlink written 5 months ago by jaqx00850
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 700 users visited in the last hour