R/intersectXMLAnnot.R

Defines functions intersectXMLAnnot.internal intersectXMLAnnot

Documented in intersectXMLAnnot

intersectXMLAnnot <- function(tabSpecies, annot, level="gene", flanking=NULL){
  res <- list()
  for(i in 1:nrow(tabSpecies)){
    res[[i]] <- intersectXMLAnnot.internal(tabSpecies=tabSpecies[i,], annot=annot, level=level, flanking=flanking)
  }
  res <- do.call(rbind, res)
  res
}

intersectXMLAnnot.internal <- function(tabSpecies, annot, level, flanking){
  start <- min(c(tabSpecies$hitStart,tabSpecies$hitEnd))
  end <-  max(c(tabSpecies$hitStart,tabSpecies$hitEnd))
  if(!is.null(flanking)){
    flanking <- 1000 * flanking
    if(length(flanking)==1) flanking <- c(flanking, flanking)
    start <- start - flanking[1]
    end <- end + flanking[2]
  }
  tempAnnot <- annot[annot$V3==level,]
  tempAnnot <- tempAnnot[tempAnnot$V1==tabSpecies$hitChr]
  tempAnnot <- tempAnnot[(as.numeric(tempAnnot$V4)>=start) & (as.numeric(tempAnnot$V5)<=end),]
  tempAnnot$origChr <- tabSpecies$origChr
  tempAnnot$origStart <- tabSpecies$origStart
  tempAnnot$origEnd <- tabSpecies$origEnd
  tempAnnot$hitChr <- tabSpecies$hitChr
  tempAnnot$hitStart <- tabSpecies$hitStart
  tempAnnot$hitEnd <- tabSpecies$hitEnd
  tempAnnot
}

Try the hoardeR package in your browser

Any scripts or data that you put into this service are public.

hoardeR documentation built on May 29, 2017, 11:04 a.m.