This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to get the gene names corresponding to genes in a module in R?

On doing module extraction from a rna-seq dataset, I get the module as a text file containing the index number of the gene and not the gene names. I have saved the gene names from the original gene expression file in a variable "geneNames". How do I match the index number from the module file with the index number of geneNames to get the corresponding gene name for the genes in the module? The coding language used is R.

gene rna-seq r

1 answer

geneNames
[1] "Gene1" "Gene2" "Gene3" "Gene4"

Import your text file back into R. If there are column names in your text file, set col_names = TRUE

module <- read.tsv(file = "textfie.txt", col_names = FALSE)
module
1 2
2 3
3 1

In R, you can extract values from a vector using the position. So in this case, the positions are in the first column of the data frame.

geneNames[module[[1]]]
"Gene2" "Gene3" "Gene1"

Log in to answer this question.