I have the following object in a basic DESeq2 bulk RNA-seq differential expression pipeline (human data). It filters out the genes that have low counts but on top of that I would like to remove a couple of genes that I know have issues in my dataset, and want to see how my analysis looks without them. I have the list of such genes in a vector named "genes" and it's encoded as gene symbols (I could transform them to EnsemblIDs if needed).

    genesToRemove<- c("gene1","gene2","gene3","gene4","gene5","gene6")

    dds <- DESeqDataSetFromHTSeqCount(sampleTable = mytable,directory = directory,design= ~ condition)
    
    dds
    
    class: DESeqDataSet 
    dim: 60725 326 
    metadata(1): version
    assays(1): counts
    rownames(60725): ENSG00000278625.1 ... ENSG00000277374.1
    rowData names(0):
    colnames(326): 9275 9351 ... 10146 10199
    colData names(5): Condition Age ...
    
    genes_to_keep <- rowSums(counts(dds)) >= 50
    dds2 <- dds[genes_to_keep,]


I would like to do it at this point, after this code, so that then I keep going without them. The problem is that I am not sure how to access the part of the dds2 object where you have the genes in order to filter them out. Any thoughts? Thank you.

Hi!

In this case you could try this one:

    #Obtain the indices of only desired genes
    genesToRemove <- which(!rownames(dds) %in% genesToRemove)

    #Cut your desired genes in the DESeq object
    dds <- dds[genesToRemove, ]

    #Verify that undesired genes are removed from DESeq object
    genesToRemove %in% rownames(dds)

And the result must be `FALSE` for every undesired gene.

Best regards!