Correlation heatmap for two datasets
Hi, I want to correlate two matrices of data. First matrix is metabolomic data with 8 biological replicates and 51 metabolites. Second matrix is the transcriptomic data with 8 replicates and 64 transcripts.
Metabolomic data
ID A A A A B B B B
1 1489 1285 478 125 148 125 128 489
2 12145 25 265 454 8926 526 565 558
...... and 50 more rows like this
Transcriptomic data
ID A A A A B B B B
1 148 12 278 125 148 185 28 48
2 12145 25 75 454 8926 56 565 58
...... and 64 more rows like this
How should I organize the input file? what is the code to run in R?
Thanks
Maria
• 4,988 views
•
link
1 answer
Possible solution. Here taking a random data. This script will calculate pair wise correlation matrix between all metabollites and transcripts. You organize the data such that first column will contain your ID. Then use read.table function as shown below to read the data into R
M = read.table(file="metab.txt", sep="\t", header=T, stringsAsFactor=F)
T = read.table(file="transc.txt", sep="\t", header=T, stringsAsFactor=F)
Here is the demo code
# Random metaboliite and transcriptome data
# Id: M1 to M51 and T1 to T64 in first col
M = data.frame( ID = paste("M", 1:51, sep=""), matrix(rnorm(51*8), ncol=8))
T = data.frame( ID = paste("T", 1:64, sep=""), matrix(rnorm(64*8), ncol=8))
cormat= matrix(0, nrow=nrow(M), ncol=nrow(T))
head(M);
head(T);
for(i in 1:nrow(M))
{
for(j in 1:nrow(T))
{
cormat[i,j] = cor(unlist(M[i,-1]), unlist(T[j,-1]))
}
}
library("corrplot")
corrplot(cormat) # Correalion heatmap
heatmap(cormat); # Heatmap function of base graphics.
You have to beautify heatmap.
Hope this is what you expect.
• 1 views
•
link
Log in to answer this question.
Do these data are already in R or in a spreadsheet ?
You have to identify your replicates, like A1, A2... B1, B2
You can use read.table to import your files in R
What do you want to achieve ?