Esempio n. 1
0
 /**
  * Initialise a CTMain before usage with a first tree, going through and setting up the hash table
  * etc.
  *
  * @param root Root of the initial tree to initialise with
  * @param noOfSamples Current number of samples taken
  */
 public void initialize(TreeNode root, int noOfSamples) {
   // Parameter initialisation
   this.noOfSamples = noOfSamples;
   noOfTrees = 0;
   // TaxaMap initialisation
   List<TreeNode> leaves = root.getLeaves();
   noOfTaxa = leaves.size();
   // Hash initialisation
   hashUtils = new HashUtils();
   hashUtils.initialize(noOfTaxa, noOfSamples, C, seed);
   hashTable = new HashTable(hashUtils.m1);
   // Taxamap initialisation
   taxa = new TaxaMap(noOfTaxa);
   for (int i = 0; i < leaves.size(); i++) {
     taxa.put(leaves.get(i).name, i);
   }
   leafEdgeLengths = new double[noOfTaxa];
   // Adds a single star partition, once and for all.
   BitSet star = new BitSet(noOfTaxa);
   star.flip(0, noOfTaxa);
   HashEntry entry = new HashEntry(-1, star, 0.0d);
   entry.count = noOfSamples + 1;
   partitions.add(entry);
   // Majority threshold initialisation
   updateInterestThreshold();
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
  /**
   * FOR TESTING ONLY Function called to initialise the Network Tester hash table & rest of CTMain
   *
   * @param noOfTestTaxa Number of taxa
   * @param noOfTestSamples number of trees input
   */
  public void InitialiseNetworkTester(int noOfTestTaxa, int noOfTestSamples) {
    // TaxaMap initialisation
    noOfTrees = 0;
    noOfTaxa = noOfTestTaxa;
    noOfSamples = noOfTestSamples;
    // Hash initialisation
    hashUtils = new HashUtils();
    hashUtils.initialize(noOfTaxa, noOfSamples, C, seed);
    hashTable = new HashTable(hashUtils.m1);
    leafEdgeLengths = new double[noOfTaxa];
    taxa = new TaxaMap(noOfTaxa);
    for (int i = 0; i < noOfTaxa; i++) {
      taxa.put("" + i, i);
      leafEdgeLengths[i] = 1;
    }

    // Adds a single star partition, once and for all.
    BitSet star = new BitSet(noOfTaxa);
    star.flip(0, noOfTaxa);
    HashEntry entry = new HashEntry(-1, star, 0.0d);
    entry.count = noOfSamples + 1;
    partitions.add(entry);
    updateInterestThreshold();
  }