Cannot great a gene by gene matrix in Rstudio
1
0
Entering edit mode
2.9 years ago
Bioman • 0

So the lecture I have made no comment on how to make a distance matrix like the one in the picture, and any online help seems to also gloss over this matrix build

https://imgur.com/a/DJZfVf6

Is it simply impossible? or so easy there exits no notes for it

Thanks in advance

gene matrix • 803 views
ADD COMMENT
1
Entering edit mode
2.9 years ago
Pratik ★ 1.0k

Hey so if you have a gene expression matrix with genes as your row names and cells/samples as your columns, then you can do the following within R:

matdf <- as.matrix(df)
transposed.matdf <- t(matdf)
matdf.cor <- cor(transposed.matdf, y = NULL, use = "pairwise.complete.obs", method = c("pearson"))

df.dist.mat <- as.dist(1 - matdf.cor)

and then you probably know this to see the top 5 lines of the head of the matrix do:

head(df.dist.mat)

Here's what helped me when I was doing this to make gene-gene correlation matrix for gene clustering:

https://bio723-class.github.io/Bio723-book/clustering-in-r.html#hierarchical-clustering-in-r

Hope this helps!

ADD COMMENT
0
Entering edit mode

Hej I really appreciate the help, but the biggest issue is not the methodical coding in of itself. But the creation of the gene by gene distance matric in my picture, at the bottom.

It's for note taking, and for some reason I cannot make a matrix like the one in the picture, without resulting to hard coding. Is there anyway to make a matrix containing the subtracted value between each possible combination of 3 genes containing 3 velues?

ADD REPLY
0
Entering edit mode

gene 1 = 2

gene 2 = 3

gene 3 = 6

You subtract the column value with the row value, and then take the absolute value of the resulting number.

What is distance?

"Distance is the absolute value of the difference between the two points." Source: flexbooks.ck12.org

when a number or expression is surrounded by | it means take the absolute value of it

gene1 by gene1 = |2 - 2| = 0

gene 2 by gene 1 = |3-2| = 1

gene 1 by gene 2 = |2-3| = |-1| = 1

Please let me know if this clicks. If you need more help I could draw it out for you.

ADD REPLY

Login before adding your answer.

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