R/longest-suffix.R

## Returns the longest suffix of path in a PST

lsuffix <- function(PST, path, asc=FALSE) {

	if (length(path)==1) { path <- seqdecomp(path) }
	sl <- length(path)
	
	if (asc) {
		lsuf <- sl
		while (paste(path[lsuf:sl], collapse="-") %in% rownames(PST[[sl-lsuf+1]]) & lsuf > 1) {
			lsuf <- lsuf-1
		}
	} else {
		lsuf <- 1
		while (!paste(path[lsuf:sl], collapse="-") %in% rownames(PST[[sl-lsuf+1]] ) & lsuf < sl) {
			lsuf <- lsuf+1
		}
	}

	message(" [>] longest suffix in the tree is: ", paste(rev(path[1:lsuf]), collapse="-"))

	return(path[1:lsuf])
}

Try the PST package in your browser

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

PST documentation built on May 2, 2019, 5:14 p.m.