Hello,
My plan is to do differential expression analysis with DESeq2 package from the count data that I have obtained from Kallisto software (alignment-free tool). I have two samples. So, I did as below:
> datadir <- "/scratch/gh/"
> meta <- read.delim(paste0(datadir, "/se/se_meta.txt"),
header = TRUE, as.is = TRUE)
> rownames(meta) <- meta$names
> meta$trt <- factor(meta$trt)
> meta$cell <- factor(meta$cell)
#
> library(tximport)
> files <- list.files("/scratch/gh/se/kallisto/",
pattern = ".*-abundance.tsv",
full.names = TRUE)
> tx <- suppressMessages(tximport(files = files,
type = "kallisto",
txOut = TRUE))
### The tx object contains the transcript expression extimates of my two samples.
> tx.counts <- round(tx$counts)
> colnames(tx.counts) <- sub("_.*","",basename(files))
#
### Next, I summarised them at the gene level:
> tx2gene <- data.frame(
TX=rownames(tx.counts),
GENEID=sub("\\.\\d+$","",rownames(tx.counts)))
#
> count.table <- round(summarizeToGene(tx, tx2gene)$counts)
> colnames(count.table) <- sub("_.*","",basename(files))
#
> class(count.table)
[1] "matrix"
#
Now, to be able to do differential expression analysis with DESeq2 package, I need to build a DESeqDataSet objest from my count matrix which is count.table. However, when I run the below code, I get the following ERROR:
#
> stopifnot(all(colnames(count.table) == rownames(meta)))
Error: all(colnames(count.table) == rownames(meta)) is not TRUE
I also ran the below codes to see what is different between my rownames(meta) and colnames(count.table):
> colnames(count.table)
[1] "SRR6822797-sortmerna-trimmomatic-abundance.tsv"
[2] "SRR6822798-sortmerna-trimmomatic-abundance.tsv"
> rownames(meta)
[1] "SRR6822797" "SRR6822798"
I think to fix this ERROR, I need to have my colnames(count.table) as exactly like my rownames(meta). Would you please help me how to make the output of my colnames(count.table) as "SRR6822797" "SRR6822798" ?
Thank you very much.
Please try and solve your R problems before posting questions on a specialized website like Biostars.
You can generalize your problem like: "how to change rownames of a matrix" and google that.
Otherwise you can try and understand the code you posted, if you didn't write it yourself, as you already have the solution there.
Please use the formatting bar (especially the
code
option) to present your post better. I've done it for you this time.Thank you!
Did you try
colnames(count.table) <- rownames(meta)
?