R/getProfiles.R

Defines functions getProfiles

Documented in getProfiles

getProfiles <- function(eSet, probeAnno, gffAnno, upstream, downstream, feature="ORF", borderNames, method, sameLength=T, fill=T, distance=8, spacing=4) {
	
	stopifnot(all(c("chr", "start", "end", "strand") %in% names(gffAnno)))
	gffAnno$chr <- as.vector(gffAnno$chr)
	gffAnno$name <- as.vector(gffAnno$name)	

	chr <- unique(unlist(lapply(ls(probeAnno), strsplit, split="(\\.start|\\.unique|\\.end|\\.index)", perl=T)))
	chr <- intersect(chr, gffAnno$chr)

	if(length(chr) == 0) stop("No chromosomes in gff annotation mapped in probeAnno object.")
		

	profile <- list()
	profile[["ID"]] <- colnames(exprs(eSet))
	profile[["upstream"]] <- upstream
	profile[["downstream"]] <- downstream
	profile[["method"]] <- method
	profile[["borderNames"]] <- borderNames
	profile[["feature"]] <- feature
	
	if(method == "middle") {
		cat("Mapping annotated features to spotted probes \n")
		featureMap <- mapFeatures(probeAnno, gffAnno, upstream, downstream, chr)
		cat("Getting probe intensities \n")
		distribution <- getIntensities(eSet, chr, featureMap, gffAnno)
		#distribution <- lapply(distribution, function(x) {if(! all(is.na(distribution))) {return(x)}})
		if(fill) {
			cat("Filling gaps with NAs\n")
			distr <- fillNA(distribution, featureMap, upstream, downstream, gffAnno, distance, spacing)
			
			if(sameLength) {
				cat("Making equal lengths for upstream/downstream regions\n")
				distr <- sameLength(distr)
				profile[["profile"]] <- distr
				return(profile)
			}
			else {
				profile[["profile"]] <- distr
				return(profile)
			}
		}
		else {
			profile[["profile"]] <- distribution
			return(profile)
		}
	}
	else if(method == "basewise") {
		profile[["profile"]] <- getProfilesByBase(eSet, probeAnno, chr, gffAnno, upstream, downstream)
		return(profile)
	}
}

Try the Starr package in your browser

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

Starr documentation built on April 28, 2020, 7:52 p.m.