Thx for your reply. I tried changing the call to
dds <- DESeqDataSetFromMatrix(countData = as.matrix(all_counts),
colData = data.frame(c('gene', 'cell1', 'cell2')))
But I'm still getting the same error message.
Hi, I'm trying to use DeSeq2 to calculate gene expression levels.
My count table (all_counts) looks like this
gene cell1 cell2
1 ENSMUST00000000001 712 1613
2 ENSMUST00000000003 0 0
3 ENSMUST00000000010 2 3
4 ENSMUST00000000028 0 0
5 ENSMUST00000000033 0 0
I'm call DESeqDataSetFromMatrix
dds <- DESeqDataSetFromMatrix(countData = all_counts,
colData = data.frame(c('gene', 'cell1', 'cell2')))
But I'm always getting this error
Error in DESeqDataSet(se, design = design, ignoreRank) :
some values in assay are negative
But there are no negative values. I verified this by
> any (!is.integer(all_counts[,2]))
[1] FALSE
> any (!is.integer(all_counts[,3]))
[1] FALSE
> any (all_counts[,2] < 0)
[1] FALSE
> any (all_counts[,3] < 0)
[1] FALSE
Any ideas what I'm doing wrong?
From the manuals the countData must be a numeric matrix, from your example all_counts, it looks like a dataframe.
Try to convert it to matrix:
countDataMatrix <- as.matrix(all_counts[ , -1])
And keep the names of the genes in the rownames (as suggested by @DevonRyan in the comments):
rownames(countDataMatrix) <- all_counts[ , 1]
Thx for your reply. I tried changing the call to
dds <- DESeqDataSetFromMatrix(countData = as.matrix(all_counts),
colData = data.frame(c('gene', 'cell1', 'cell2')))
But I'm still getting the same error message.
Try dropping the first column: countData = as.matrix(all_counts[ , -1]
Thank you very much, this works. So do I have to store the gene ids by my self in an extra vector or is there a better way how to keep the gene ids associated with the rows?
In this example they don't have to drop the gene ids but I don't know why it's not working in my case: https://informatics.fas.harvard.edu/differential-expression-with-deseq2.html
Set the gene IDs to be the row names of the matrix.
I had the same problem, but also needed to set the column names explicitely and set the matrix content to integers. So I also want share what worked for me:
ctsTable <- read.table(ctsFile_path, sep="\t", header=FALSE, stringsAsFactors=FALSE)
countDataMatrix <- as.matrix(ctsTable[-1,-1]) # Extract counts & Ignore first column (geneID) and first row (sample names)
mode(countDataMatrix) <- "integer" # Convert to integer
rownames(countDataMatrix) <- ctsTable[-1,1] # Set rownames to geneIDs
colnames(countDataMatrix) <- ctsTable[1,-1] # Set colnames to sample names
dds <- DESeqDataSetFromMatrix(countData = countDataMatrix)
Log in to answer this question.