Entering edit mode
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
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |