R/tree.tiers.R

Defines functions get.num.tiers

get.num.tiers <- function(tree) {
    tiers <- rep(0, nrow(tree));

	get.tiers <- function(node.id) {
	    # Need to exclude NA values because comparison is bypassed
	    # NA values return NA instead, so children could be c(NA, -1)
		children <- tree$id[tree$parent == node.id & !is.na(tree$parent)];

		for (child in children) {
			tiers[tree$id == child] <<- tiers[tree$id == node.id] + 1;
			get.tiers(child);
		    }
	    }

	root.node <- '-1';
	get.tiers(root.node);

	return(tiers);
    }

Try the CancerEvolutionVisualization package in your browser

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

CancerEvolutionVisualization documentation built on Nov. 22, 2023, 1:08 a.m.