heatmap for a predetermined order of rows
2
0
Entering edit mode
8.9 years ago
kanwarjag ★ 1.2k

I generated a heat map where I have order of rows via which these are arranged. I want to use this order to plot another set of control samples to show side by side pattern. What should be the best way to do this pattern. Perhaps we may be able to do it in R or any other tool? I have only 500 rows and 3 columns

Thanks

ordered matrix • 9.0k views
ADD COMMENT
0
Entering edit mode
8.9 years ago

Simply reorder the rows of your second matrix to match the first one, then use for example R's heatmap() function setting Rowv=FALSE to prevent it from automatically reordering the rows, alternatively, you could set Rowv to a vector defining the order.

ADD COMMENT
0
Entering edit mode

What is have is I ran the clustering and have

ClusterOrder <- row.names(dat[hv1$rowInd,])
head(ClusterOrder)
write.table(ClusterOrder,file="File1.txt",sep="\t")

Now I want to use File 1 order to sort the second file (File2) both files have unique matching probe id

I dont want to include my control data along with clustering as it affect ordering. I did not clarify clearly in the first instance

ADD REPLY
0
Entering edit mode

Use the match() function to reorder you second data set based on ClusterOrder. Something like:

data2[match(ClusterOrder,row.names(data2)),]
ADD REPLY
0
Entering edit mode
8.9 years ago
dally ▴ 210

Do you have a "Gene" name or similar column that are identical between both data sets? If so then the merge() function in R could do this fairly easily.

Something like this should work fairly well (ignore the .cdt file extensions, this will work for most tab delimited data sets).

# Set your working directory.
setwd("~/workspace/GenomicsData/analysis/visualization/homerheatmaps/")

# Read in your files (cdt's are tab-delimited). File1 should be your sorted cdt file.
# File2 should be the cdt file you want to sort.
file1 <- read.delim("groseqheatmap_sorted.cdt")
file2 <- read.delim("hexim_heatmap.cdt")

# Merge the files together into a seperate file called file3 for easy write-out.
# Here we are sorting by gene, but any column name is appopriate (as well as number).
file3 <- merge(file1["Gene"], file2, by="Gene", sort=FALSE)

# Write out file3 for easy altering in text editor.
# file = "whatever_you_want_to_name_your_output_file"
write.table(x = file3, file = "hexim_sortedtogroseq.cdt", sep = "\t", quote = FALSE, row.names = FALSE)
ADD COMMENT

Login before adding your answer.

Traffic: 1793 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6