How to subset S4 list with 5 Granges elements
1
0
Entering edit mode
5.2 years ago

I have a S4 list (peakAnnoList) which contains many Chip-Seq data in the Granges format.

I would like to subset/filter peakAnnoList based on one of its slot ($width > 4000). Here is the code to generate peakAnnoList:

  ## loading packages
library(ChIPseeker)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
library(clusterProfiler)

files <- getSampleFiles()
peakAnnoList <- lapply(files, annotatePeak, TxDb=txdb,
                       tssRegion=c(-3000, 3000), verbose=FALSE)

peakAnnoList is a list with 5 elements and each elements contains combination of "csAnno" and "GRanges" and some other objects. I would like to filter all 5 elements of peakAnnoList for width > 4000. Here is the position of width (peakAnnoList[[1]]@anno@ranges@width). I can do that with only 1 elements of list by converting it to data.frame, but I would like to have it for all the elements.

ChIP-Seq • 1.2k views
ADD COMMENT
1
Entering edit mode

It's the problem of R dataframe and file handling. Please tag R, data.frame and related tags. Also, please provide the file sample from which you want to extract the data. Without knowing S4 list structure it's hard to imagine the solution.

ADD REPLY
0
Entering edit mode
5.2 years ago
Ram 43k

You should look into apply family of functions, especially lapply. Given that peakAnnoList is a list, you should be able to

filteredItems <- lapply(peakAnnoList, 
                            function(item) {
                                if(item@anno@ranges@width > 4000)
                                    return(item)
                            }
                        );
ADD COMMENT

Login before adding your answer.

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