R/pScore.R

#' @export

#this function calculate the p score (using window sizes of number of RE sites and bp)

pScore <- function(filename,vp.chrom,vp.pos,erase,wind,REs)
{
	dat<-filename
	#for now i'm not going to use the removing of the sections in cis. it isn't compatible with some other functions in the program
	#dat<-dat[dat[,1]!=vp.chrom | (dat[,1]==vp.chrom & (dat[,2]<(vp.pos-erase) | dat[,2]>(vp.pos+erase))),]
	nothing <- erase #this is just so there is a use for 'erase'. it is not really needed, and should be taken off once the line above is returned
	sizdat <- nrow(dat)
	pVal <- rep(0,sizdat)
	chr <- unique(dat[,1])
	ind <- 1
	for (j in 1:length(chr))
	{
		tmp.data<-dat[dat[,1]==chr[j],]
		prob<-sum(tmp.data[,3]>0)/nrow(tmp.data)
		for (i in 1:nrow(tmp.data))
		{
			first<-i-REs
			last<-i+REs
			if (first<1){first<-1}
			if (last>nrow(tmp.data)){last<-nrow(tmp.data)}
			tmp<-tmp.data[first:last,]
			index<-which(abs(tmp[,2]-tmp.data[i,2])<wind/2)
			pVal[ind] <- binom.test(sum(tmp[index,3]>0),length(index),prob,alternative="greater")$p.value
			ind <- ind + 1
		}
	}
	ps <- -log10(pVal)
	ps[ps == Inf] <- max(ps[ps != Inf])
	ps <- cbind(dat[,1],dat[,2],ps)
	return(ps)
}
akivab2/Analyze4CPackage documentation built on May 6, 2019, 11:45 a.m.