This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Code to find the list of genes in the DEG table in R?

Hello to all

I have a list of invasive genes, on the other hand I have a DEG table, now I want to know if my list of genes is in the DEG table or not? How can I do this in R? With what code?

Thanks in advance

r

instead of subsetting, just do an enrichment testing.

2 answers

You could use intersect(). Assuming invasive is a vector of invasive genes and df is your DEG table containing a column gene, you would do :

intersect(invasive, df$gene)

You can use the %in% operator in R to ask "is this in that"? The result will be a boolean vector, which you can use to return any positions of your data frame that are TRUE. For example:

# create a data frame with 2 columns of experimental results
DEgenes <- data.frame(exp1_FC=rnorm(20), exp2_FC=rnorm(20))

# assign gene names to the rows
rownames(DEgenes) <- paste0("g", 1:nrow(DEgenes))

# make a vector of invasive genes
invasive <- c("g3", "g7", "g11", "g3145")

# Are any of the DE genes in our invasive vector?
DEgenes[rownames(DEgenes) %in% invasive,]

        exp1_FC    exp2_FC
g3  -0.04853683 -0.8079399
g7  -0.21303331  0.3234412
g11  0.30011850 -0.2239166

Log in to answer this question.