R/PeakML.Methods.getGroupAnnotations.R

Defines functions PeakML.Methods.getGroupAnnotations

Documented in PeakML.Methods.getGroupAnnotations

PeakML.Methods.getGroupAnnotations <- function(PeakMLtree=NULL,filename=NULL)
{
	if (!is.null(filename))
	{
		st <- system.time(PeakMLtree <- xmlInternalTreeParse(filename))
	}

	setidsrecord <- function (setid)
	{
		STR <- paste ("sapply(getNodeSet(PeakMLtree,\"/peakml/peaks/peak[",setid,"]/annotations/annotation/label\"),xmlValue)",sep="")
		annotationnames <- eval (parse(text=STR))
		STR <- paste ("sapply(getNodeSet(PeakMLtree,\"/peakml/peaks/peak[",setid,"]/annotations/annotation/value\"),xmlValue)",sep="")
		annotationvalues <- eval (parse(text=STR))
		if (length(annotationvalues)!=0)
		{
			val <- cbind (setid,annotationnames,annotationvalues)
		} else
		{
			val <- NULL
		}
		val
	}

	nrpeakgroups <- as.numeric(sapply(getNodeSet(PeakMLtree,"/peakml/header/nrpeaks"),xmlValue))

	system.time(annots <- lapply (1:nrpeakgroups,setidsrecord))
	annots <- do.call (rbind,annots)

	annotnames <- unique (annots[,2])

	groupannotations <- matrix (ncol=length(annotnames),nrow=nrpeakgroups)

	rownums <- as.numeric(annots[,1])

	system.time({
	for (rn in 1:length(rownums))
	{
		groupannotations[rownums[rn],which(annotnames==annots[rn,2])] <- annots[rn,3]
	}
	})
	
	if (length(rownums)!=0)
	{
		attr <- vector ("list",length(annotnames))
		names(attr) <- annotnames
		for (annotid in 1:length(attr))
		{
			attr[[annotid]] <- groupannotations[,annotid]
		}
	} else
	{
		attr <- NULL
	}

	attr
}

Try the mzmatch.R package in your browser

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

mzmatch.R documentation built on May 31, 2017, 4:31 a.m.