R/interpolate.pcf.r

Defines functions interpolate.pcf

Documented in interpolate.pcf

####################################################################
## Author: Gro Nilsen, Knut Liestřl and Ole Christian Lingjćrde.
## Maintainer: Gro Nilsen <gronilse@ifi.uio.no>
## License: Artistic 2.0
## Part of the copynumber package
## Reference: Nilsen and Liestřl et al. (2012), BMC Genomics
####################################################################

### Requires:
### pullOutContent

#Function with interpolates pcf-segments
interpolate.pcf = function(segments, x) {
  
  #Make sure segments is a data frame
  segments <- pullOutContent(res=segments,what="segments")
  
  usamp = unique(segments$sampleID)
  nsamp = length(usamp) 
  chrom = unique(x[,1])
  z = data.frame(cbind(x[,c(1:2)],matrix(0,nrow(x),nsamp)))
  #z = data.frame(x[,c(1,2)], matrix(0, nrow(x), nsamp))
  names(z) = c("chr","pos",usamp)
  for (i in 1:nsamp) {
    for (j in 1:length(chrom)) {
      fitij = segments[segments$sampleID==usamp[i] & segments$chrom==chrom[j],]
      v = (c(fitij$start.pos[-1],10^9)+fitij$end.pos)/2
      xj = x[x[,1]==chrom[j],2]
      kj = rep(0,length(xj))
      for (k in rev(1:length(v))) {
        kj[xj <= v[k]] = k
      }
      z[z$chr==chrom[j],2+i] = fitij$mean[kj]
    }
  }
  return(z)
}

Try the copynumber package in your browser

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

copynumber documentation built on Nov. 8, 2020, 6:10 p.m.