0
$\begingroup$

I would like to plot the correlation between two specific genes in my data. I have a matrix with genes in rows and samples in columns, with read counts data. If I want to look at the correlation between 2 genes

1) do I need to convert the counts to some other units?

2) Is normalization needed?

I currently have counts returned by featureCounts:

          Sample1  Sample2  Sample3  Sample4  Sample5

ESAM         803    338       528       841      712
ESCO1        1594   1401      847       392      611
ESCO2         274   778       288       77       204
ESD          6192   3502      2013      1573     1808
ESF1         1356   1497      1011      372      701
ESM1         398    58        114       582      135 

I tried this way:

I transposed the above data making genes as columns and sample names as rows. I removed the rows. Lets say the genes as columns is in dataframe "df".

df.mat <- cor(df)
colnames(df.mat) <- NULL
rownames(df.mat) <- NULL
heatmap.2(df.mat, trace="none")

I have an error:

Error in .External.graphics(C_layout, num.rows, num.cols, mat, as.integer(num.figures),  : 
  invalid graphics state

I want to look at the correlation between ESCO1 and ESCO2. Can anyone tell me how to do that and plot with a small example.

$\endgroup$
0

3 Answers 3

3
$\begingroup$
  1. I suppose in an idealized world you'd use something like salmon to get TPMs, which can account for differences in effective gene length by sample. However that's quite likely to be overkill.
  2. Not necessary, you're using a with-sample ratio, which wouldn't be changed by normalization.

Here is a small example in R, assuming your matrix or data frame is named m:

first = which(row.names(m) == "ESCO1")
second = which(row.names(m) == "ESCO2")
plot(m[first,], m[second,])

or cor(m[first, ], m[second,]). You'll want a rank-based correlation.

$\endgroup$
7
  • $\begingroup$ When I did "cor(m[first, ], m[second,])" I see column names as both rows and columns and showing "NA" for all. $\endgroup$
    – beginner
    Commented May 14, 2018 at 9:18
  • 1
    $\begingroup$ Stop removing the column and row names. $\endgroup$
    – Devon Ryan
    Commented May 14, 2018 at 9:24
  • $\begingroup$ don't know what's wrong. the dataframe "df" is with column names "gene", sample1, sample2, sample3 etc...I made the first column "gene" into rows. then I got the "ESCO1" into first and other into second. Then I did cor(df[first, ], df[second,]) and didn't work. $\endgroup$
    – beginner
    Commented May 14, 2018 at 9:35
  • $\begingroup$ "It didn't work" isn't ever a useful thing to write unless immediately followed by either the error message or problematic output you received. I presume your dataframe still has the gene column, which would need to be removed, or you need to put things through c() to get a proper vector. $\endgroup$
    – Devon Ryan
    Commented May 14, 2018 at 9:40
  • $\begingroup$ @beginner when asking this sort of thing, you need to give us an example that reproduces your issue which we can run on our own machines. You are running some command with a wrong parameter, but since you don't show us the code you use, we can't help you find the mistake. Please see stackoverflow.com/help/mcve $\endgroup$
    – terdon
    Commented May 14, 2018 at 9:52
0
$\begingroup$

I'm answering my own question. I tried this way.

df <- read.csv("df.csv")

Samples ESAM    ESCO1   ESCO2   ESD ESF1    ESM1
Sample1 803     1594    274    6192 1356    398
Sample2 338     1401    778    3502 1497    58
Sample3 528      847    288    2013 1011    114
Sample4 841      392    77     1573  372    582
Sample5 712      611    204    1808  701    135

df2 <- data.frame(df[,-1],row.names = df[,1])

cormat <- round(cor(df2,use="pairwise.complete.obs"),2)
head(cormat)

library(ggcorrplot)
pdf("eg.pdf")
ggcorrplot(cormat,hc.order = TRUE,
           outline.col = "white",
           ggtheme = ggplot2::theme_gray,
           colors = c("#6D9EC1", "white", "#E46726"))
dev.off()

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ This does not answer your own question, you ask for a plot with the correlation between 2 genes, but you show a correlation plot between all your genes... $\endgroup$
    – benn
    Commented May 14, 2018 at 10:38
  • $\begingroup$ yes, this shows correlation between all the genes but also shows the genes I'm interested in. I don't know how to plot for a specific genes so , I did this. $\endgroup$
    – beginner
    Commented May 14, 2018 at 10:42
  • $\begingroup$ Down vote from me, you ask for something else in your question (plot between two genes). Impossible to 'guess' what you are really meaning. Also from your answer it is not clear if you have to normalize or not. $\endgroup$
    – benn
    Commented May 14, 2018 at 12:48
0
$\begingroup$

You can represent, and calculate, the correlations using psych:

library(psych)
pairs.panels(df,df, 
             method = "pearson", # correlation method
             hist.col = "#00AFBB",
             density = TRUE,  # show density plots
             ellipses = TRUE,xlim=c(0,500),ylim=c(0,500))
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.