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

Hey i have a dataframe (sample.annotations) that i get some paths for my datasets which are: peaks.data ( GRange object with peaks coordinations from Chip-seq experiments) and annotation.data (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:

library(ChIPpeakAnno)

peaks2genes<- NULL
for(i in 1:nrow(samples.annotations)) {
  peaks.data<- readRDS(samples.annotations$path[i])
  chr<- peaks.data[,samples.annotations$peak.coord.chr.col[i]]
  chr<- gsub("chr","",chr, perl=T,ignore.case=T)
  start<-peaks.data[,samples.annotations$peak.coord.start.col[i]]
  end<- peaks.data[,samples.annotations$peak.coord.end.col[i]]
  names <- paste("Site",1:nrow(peaks.data),sep="")
  peaksRD <- RangedData(space = chr,ranges=IRanges(start = start, end = end,names= names))
  annotation.data <- readRDS(samples.annotations$GeneAnnotationsPath[i])
  annotation.dataframe<-as.data.frame(annotation.data)
  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 • 1.8k views
ADD COMMENTlink modified 4.3 years ago • written 4.3 years ago by newscient20
1
gravatar for Devon Ryan
4.3 years ago by
Devon Ryan90k
Freiburg, Germany
Devon Ryan90k wrote:

I imagine that something like:

peaks2genes <- list()

at the beginning would be helpful

ADD COMMENTlink written 4.3 years ago by Devon Ryan90k

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

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

Help
Access

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