Reconstruct Phylogenetic Tree with Copy Number Analysis
reconstruct_tree.RdThis function reconstructs a phylogenetic tree by traversing internal nodes and computing distances between cell profiles. For each internal node, it calculates both B distance (breakpoint-aware) and G distance (general) between child nodes, then selects the reconstruction method that minimizes cost.
Arguments
- fit
A fitted model object containing:
all_input_Xs: List of input data matrices by chromosome and allele
b_dist_func: B distance function for breakpoint-aware reconstruction
g_dist_func: G distance function for general reconstruction
tree: Phylogenetic tree structure (ape format)
- chr
Character string specifying the chromosome to analyze
- allele
Character string specifying the allele type ("CN" for copy number, others for allelic)
Value
A list containing:
internal_nodes: List of reconstructed internal node profiles
deltas: List of delta values (G cost - B cost) for each internal node
merged_profiles: List of merged profiles when B distance is chosen
final_input: Final working input matrix after all reconstructions
processed_nodes: Number of internal nodes processed
chr: Chromosome identifier
allele: Allele type
Details
The function:
Sets target values based on allele type (2 for "CN", 1 for others)
Processes internal nodes in post-order traversal
For each internal node, computes B and G distances between children
Calculates delta = G_cost - B_cost
Chooses B reconstruction if delta > 0, otherwise G reconstruction
Creates pseudo-cells for internal nodes and updates working dataset