Correlation heatmap for two datasets
1
0
Entering edit mode
5.8 years ago

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

R • 4.4k views
ADD COMMENT
0
Entering edit mode

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

I want to correlate two matrices of data.

What do you want to achieve ?

ADD REPLY
0
Entering edit mode
5.8 years ago
pbpanigrahi ▴ 420

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.

correlation heatmap

correlation heatmap

Basic Heatmap

heatmap output

You have to beautify heatmap.

Hope this is what you expect.

ADD COMMENT

Login before adding your answer.

Traffic: 1878 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