I hope someone can help me with this as I just cant figure it out. I have my DESEQ2 object cts, which includes all my genes. Now I only want to look at 100 genes, which are in the list "risk_genes".
I tried with cts_new <- cts[cts %in% risk_genes,] but then I am left with 0 genes.
Thank you but I have a list of 920 genes which I want to keep. Also I have 400 samples.
I cannot type every gene individually as you did with c("Gene 1", "Gene 2", "Gene 3", "Gene 4", "Gene 5") or sample_1 = c(runif(1:5)),
sample_2 = c(runif(1:5)),
sample_3 = c(runif(1:5)) for 400 samples.
Would it be possible to use a list as i tried in my code above?
Again, is there some condition you want to select rows in the gene column based on? Otherwise, if you just want specific rows that you know, just expand the slice function to the rows you want to include. It is difficult to give more specific advice without knowing what you are trying to achieve, and how.
The condition is that these genes belong to the list "risk genes".
So I have my complete dataset and my list "risk genes".
All genes (e.g. gene 2 and 3 in above example from "risk genes") should be extracted from the complete dataset.
Based on your example, it appears that Gene is not a column of your data.frame, but rather the rownames. You can deal with this by either assigning a new column as the rownames, or filtering on the rownames.
Preamble: since DESeq2 is a bioconductor package, you will likely have better luck getting help over at the bioconductor support site.
It looks like you are trying to subset cts down to a few set of genes, and I'm guessing that your cts object is a DESeqDataSet, which isn't like a data.frame or tibble at all, so functions that work on those (like filter, etc.) will not work here.
A DESeqDataSet is a SummarizedExperiment, and you can learn the basics of what this data structure is, and how to manipulate it from this vignette.
@aka.dr.house's suggestion should work, though, because you can index into the genes (rows) and samples (columns) of your DESeqDataSeq by slicing it as if it were a 2d matrix.