Question: Iterate over Rangeddata in R with a for loop
gravatar for newscient
5.3 years ago by
European Union
newscient20 wrote:

Hey i have a dataframe (sample.annotations) that i get some paths for my datasets which are: ( GRange object with peaks coordinations from Chip-seq experiments) and (GRanges with gene annotations from ensembl). I can successful use the annotatePeakInBatch() function in R through ‘ChIPpeakAnno’ package.

As i have many datasets i want to run it iteratively (trying to do it with a for loop) and fill in an empty list with the RangedData objects that come out of the annotatePeakInBatch() function.I cant do that in R as a relatively new programmer, but the code is correct because i get annotations if i run it for specific datasets. My problem is somewhere on the iteration path!

Anyone can pin point any mistake on the following code? I keep on getting the following mistake :

Error in peaks2genes[[i]] <- annotatePeakInBatch(peaksRD, AnnotationData = annoRD) : 
  invalid type/length (S4/0) in vector allocation

My code:


peaks2genes<- NULL
for(i in 1:nrow(samples.annotations)) {<- readRDS(samples.annotations$path[i])
  chr<- gsub("chr","",chr, perl=T,
  names <- paste("Site",1:nrow(,sep="")
  peaksRD <- RangedData(space = chr,ranges=IRanges(start = start, end = end,names= names)) <- readRDS(samples.annotations$GeneAnnotationsPath[i])
  annoRD <- RangedData(space = annotation.dataframe$seqnames,ranges = IRanges(start = annotation.dataframe$start, end = annotation.dataframe$end, names = annotation.dataframe$gene_id),strand = annotation.dataframe$strand)
  peaks2genes[[i]] <- annotatePeakInBatch(peaksRD,AnnotationData = annoRD)
iteration for loop tool chip-seq • 2.3k views
ADD COMMENTlink modified 5.3 years ago • written 5.3 years ago by newscient20
gravatar for Devon Ryan
5.3 years ago by
Devon Ryan95k
Freiburg, Germany
Devon Ryan95k wrote:

I imagine that something like:

peaks2genes <- list()

at the beginning would be helpful

ADD COMMENTlink written 5.3 years ago by Devon Ryan95k

Thanks, that was it ( i feel kind of dumb but thanks again)

ADD REPLYlink written 5.3 years ago by newscient20
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2317 users visited in the last hour