R/HotspotsPrediction.R

Defines functions HotspotsPrediction

Documented in HotspotsPrediction

##' HotspotsPrediction: Count number of true CNVs in each hotspots. 
##'
##' Unknown
##' @title HotspotsPrediction
##' @param Hotspots: Unkown.
##' @param df: Data frame. Unknown.
##' @return Data frame with predicted hotspots.
##' @author Marcelo Bertalan, Louise K. Hoeffding.
##' @source \url{http://biopsych.dk/iPsychCNV}
##' @export
##' @examples Unknown. 
##'

HotspotsPrediction <- function(hotspots, df)
{ 	
	library(iPsychCNV)	
	Res <- apply(hotspots[,c("Start", "Stop", "Chr", "NumSNPs", "CN", "CNVmean", "sd")], 1, function(X)
	{
		StartH <- as.numeric(X[1]);
		StopH <- as.numeric(X[2]);
		ChrH <- X[3];
		NumSNPsH <- as.numeric(X[4]);
		CNH <- as.numeric(X[5]);
		CNVmeanH <- as.numeric(X[6]);
		sdH <- as.numeric(X[7]);
		ID <- paste(ChrH, StartH, StopH, sep=".", collapse="")

		tmp <- subset(df, Start < StopH & Stop > StartH & Chr %in% ChrH ) # & CN == CNH
		tmp$overlap <- tmp$NumSNPs/NumSNPsH
		tmp2 <- subset(tmp, overlap > 0.7)

		df <- data.frame(CNVs=nrow(tmp2), CN=CNH, NumSNPs=NumSNPsH, ID=ID, CNVmean=CNVmeanH, sd=sdH, stringsAsFactors=F)
		return(df)
	})
	tmp2 <- MatrixOrList2df(Res)
	return(tmp2)
}
mbertalan/iPsychCNV documentation built on June 30, 2017, 2:02 a.m.