/** * Create partitions from an input tree - recursive so will be called by many nodes, beginning * with root but with calculations actually beginning on leaves. * * @param partitions Partitions in the form of entries in the hash table * @param curInterestPercentage Current percentage of interest that we want splits to occur above * to view in the network later */ private ArrayList<Cluster> constructClusters( LinkedList<HashEntry> partitions, double curInterestPercentage) { ArrayList<Cluster> clusters = new ArrayList<Cluster>(); // Thresholds for the current run of the cluster builder (c.f. the threshold for the partitions // list). double curInterestThreshold = (double) (noOfTrees * (curInterestPercentage / 100.0d)); int majInterestThreshold = (int) (noOfTrees * (50.0 / 100.0d)); for (Iterator<HashEntry> it = partitions.iterator(); it.hasNext(); ) { HashEntry entry = it.next(); // Checks if this partition is still above threshold... partition. // If not: remove it - O(1). if ((double) entry.count <= curInterestThreshold) { // correct the isMajority flag to now refer to majority not if of interest or not.. if (entry.count <= majInterestThreshold) { entry.isMajority = false; } it.remove(); continue; } // Constructs clusters (list of TreeNode's for each set bit) from each partition. if ((double) entry.count > curInterestThreshold) { Cluster cluster = new Cluster(); if (entry.count > majInterestThreshold) { cluster.isMajority = true; } cluster.aboveSplit = entry.partition; cluster.noOfOccurrences = entry.count; cluster.edgeLength = entry.edgeLengthsSum / entry.count; for (int i = 0; i < entry.partition.size(); i++) { if (entry.partition.get(i)) { TreeNode node = new TreeNode(taxa.getName(i)); node.edgeLength = leafEdgeLengths[i] / noOfTrees; cluster.add(node); } } clusters.add(cluster); } } // Sort by number of taxa. // TODO: This might obviously be optimized a bit, e.g. with a PriorityQueue. - Eiriksson Collections.sort(clusters); return clusters; }