I am trying to rearrange the columns in my pheatmap, but I can't!
How do I do it?
I have bulk sequencing data were each sample preparation (Prep; 10 preps) has been subjected to two conditions (Condition; 2 conditions). I then get a heatmap of genes, but I want the columns of the heatmap to be arrange so that the columns are:
Prep1_Condition1, Prep1_Condition2, Prep2_Condition1, Prep2_Condition2, etc...
(I have a picture of this heatmap below. As you can see, the Preps don't come in pairs, and it is not like it comes with the first 10 columns being 1 condition, followed by the next 10 columns being the other condition, either!)
However, they are currently seemingly random. I have tried to mess around with dendsort but it hasn't done what I hoped!
The code I have used is:
library("DESeq2") seqdata <- read.delim("Z:/featureCount.txt", stringsAsFactors = FALSE) head(seqdata) dim(seqdata) countdata <- seqdata[,-(1)] rownames(countdata) <- seqdata[,1] # sample info (e.g. preparation ID (Prep) and experimental condition (Condition)) sampleinfo <- read.delim("Z:/SampleInfo.txt") dds <- DESeqDataSetFromMatrix(countData = countdata, colData = sampleinfo, design = ~ Condition+Prep) keep <- rowSums(counts(dds)) >= 10 dds <- dds[keep,] dds <- DESeq(dds) res <- results(dds) rld <- rlog(dds) topVarGenes <- head(order(-rowVars(assay(rld))),30) mat <- assay(rld)[ topVarGenes, ] mat <- mat - rowMeans(mat) df <- as.data.frame(colData(rld)[,c("Condition","Prep")]) pheatmap(mat, annotation_col=df)
Thank you for your help!!