[BioC] Granges averaging

Yannick Wurm y.wurm at qmul.ac.uk
Tue Oct 2 19:07:16 CEST 2012


Hello, 

my Granges object "bigGranges" contains too much data. THat makes plotting extremely slow. Sometimes I want an averaged overview. I use the following code below to obtain it. Subsequently I can use ggbio for plotting. 
But I feel there must be an elegant one-line manner of doing this?

Thanks  & kind regards,
yannick 



## code is more legible on https://gist.github.com/c5a553bd012876effb48 


averageGranges  <- GRanges()
interval_length <- 10000

for (scaffold_index in 1:nrow(myscaffolds)) {
    scaffold        <- myscaffolds$id[scaffold_index]
    scaffold_length <- myscaffolds$to[scaffold_index]
    
    num_intervals   <- scaffold_length / interval_length
    
    for (interval_index in 0:(num_intervals-1) ) {
       grangesInterval  <- GRanges(scaffold, IRanges(interval_index * interval_length, 
                                                  min( scaffold_length, 
                                                       (interval_index+1)* interval_length )))
       subsetGranges <- subsetByOverlaps( bigGranges , grangesInterval) 
       
       grangesInterval$averagemyValue <-  mean(subsetGranges$myValue)
       averageGranges <- append(averageGranges, grangesInterval)
    }
}

# then I use averageGranges

--------------------------------------
Yannick Wurm http://yannick.poulet.org
Ants, Genomes & Evolution ⋅ y.wurm at qmul.ac.uk ⋅ skype:yannickwurm ⋅ +44 207 882 3049
5.03A Fogg ⋅ School of Biological & Chemical Sciences ⋅ Queen Mary, University of London ⋅ Mile End Road ⋅ E1 4NS London ⋅ UK
Easy custom BLAST interface: http://www.sequenceserver.com



More information about the Bioconductor mailing list