def runTest(self):
     y = True
     n = False
     for i, r in enumerate([y, y, y, n, y, n, n, y, y, n, n, y, n, y, y, y, y, y, y, n, y, n, n, y, y, n, n, y, n, y, y, y, ]):
         self.assertEqual(r, treesplit.is_trivial_split(i, 0xF))
     for i, r in enumerate([y, y, y, n, y, n, n, n, y, n, n, n, n, n, n, y, y, n, n, n, n, n, n, y, n, n, n, y, n, y, y, y, ]):
         self.assertEqual(r, treesplit.is_trivial_split(i, 0x1F))
                           #0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5  6  7  8  9  0  1
     for i, r in enumerate([y, y, y, n, y, n, n, y, y, y, y, n, y, n, n, y, y, n, n, y, n, y, y, y, y, n, n, y, n, y, y, y, ]):
         self.assertEqual(r, treesplit.is_trivial_split(i, 0x17))
Example #2
0
        def countSplits(self, tc, is_rooted):
            _LOG.info(tc[0] + "; " + tc[1])
            tree_filepaths = [pathmap.tree_source_path(tc[0])]
            taxa_filepath = pathmap.tree_source_path(tc[1])
            paup_sd = paup.get_split_distribution(tree_filepaths,
                                                  taxa_filepath,
                                                  is_rooted=is_rooted,
                                                  burnin=0)
            taxon_set = paup_sd.taxon_set
            dp_sd = treesplit.SplitDistribution(taxon_set=taxon_set)
            dp_sd.ignore_edge_lengths = True
            dp_sd.ignore_node_ages = True
            dp_sd.is_rooted = is_rooted

            _LOG.debug("Taxon set: %s" % [t.label for t in taxon_set])
            taxa_mask = taxon_set.all_taxa_bitmask()
            taxon_set.lock()
            for tree_filepath in tree_filepaths:
                for tree in dataio.tree_source_iter(stream=open(
                        tree_filepath, "rU"),
                                                    schema='nexus',
                                                    taxon_set=taxon_set,
                                                    as_rooted=is_rooted):
                    self.assertIs(tree.taxon_set, dp_sd.taxon_set)
                    self.assertIs(tree.taxon_set, taxon_set)
                    treesplit.encode_splits(tree)
                    dp_sd.count_splits_on_tree(tree)

            self.assertEqual(dp_sd.total_trees_counted,
                             paup_sd.total_trees_counted)

            # SplitsDistribution counts trivial splits, whereas PAUP*
            # contree does not, so the following will not work
            #            assert len(dp_sd.splits) == len(paup_sd.splits),\
            #                 "dp = %d, sd = %d" % (len(dp_sd.splits), len(paup_sd.splits))

            taxa_mask = taxon_set.all_taxa_bitmask()
            for split in dp_sd.splits:
                if not treesplit.is_trivial_split(split, taxa_mask):
                    self.assertIn(split, paup_sd.splits)
                    self.assertEqual(dp_sd.split_counts[split],
                                     paup_sd.split_counts[split])
                    paup_sd.splits.remove(split)

            # if any splits remain, they were not
            # in dp_sd or were trivial
            remaining_splits = list(paup_sd.splits)
            for split in remaining_splits:
                if treesplit.is_trivial_split(split, taxa_mask):
                    paup_sd.splits.remove(split)
            self.assertEqual(len(paup_sd.splits), 0)
def refSplitsConflictedNull():
  global refSplitDictNull
  bm = refTre.taxon_set.all_taxa_bitmask()
  for split in refTre.split_edges:
    if not treesplit.is_trivial_split(split, bm):
      splits = refTre.taxon_set.split_as_newick_string(split)
      refSplitDictNull[splits] = []
  for j in range(0, 10000):
    refSplitDict = {}
    randomConflicts = random.sample(newickConflictedReferenceSplitList, len(targetTrees)/10)
    for split in refTre.split_edges:
      splits = refTre.taxon_set.split_as_newick_string(split)
      refSplitDict[splits] = 0
    for list in randomConflicts:
      for split in list:
        if split in refSplitDict:
  	      refSplitDict[split] += 1
    for key in refSplitDict:
      if key in refSplitDictNull:
        refSplitDictNull[key].append(refSplitDict[key])
    
  with open('nullSplits.csv','wb') as file:
    writer = csv.writer(file, delimiter='\t')
    writer.writerow(refSplitDictNull.keys())
    for row in izip_longest(*refSplitDictNull.values(), fillvalue=''):
      writer.writerow(row)
  file.close()
Example #4
0
def refSplitsConflictedNull():
    global refSplitDictNull
    bm = refTre.taxon_set.all_taxa_bitmask()
    for split in refTre.split_edges:
        if not treesplit.is_trivial_split(split, bm):
            splits = refTre.taxon_set.split_as_newick_string(split)
            refSplitDictNull[splits] = []
    for j in range(0, 10000):
        refSplitDict = {}
        randomConflicts = random.sample(newickConflictedReferenceSplitList,
                                        len(targetTrees) / 10)
        for split in refTre.split_edges:
            splits = refTre.taxon_set.split_as_newick_string(split)
            refSplitDict[splits] = 0
        for list in randomConflicts:
            for split in list:
                if split in refSplitDict:
                    refSplitDict[split] += 1
        for key in refSplitDict:
            if key in refSplitDictNull:
                refSplitDictNull[key].append(refSplitDict[key])

    with open('nullSplits.csv', 'wb') as file:
        writer = csv.writer(file, delimiter='\t')
        writer.writerow(refSplitDictNull.keys())
        for row in izip_longest(*refSplitDictNull.values(), fillvalue=''):
            writer.writerow(row)
    file.close()
        def countSplits(self, tc, is_rooted):
            _LOG.info(tc[0] + "; " + tc[1])
            tree_filepaths = [pathmap.tree_source_path(tc[0])]
            taxa_filepath = pathmap.tree_source_path(tc[1])
            paup_sd = paup.get_split_distribution(tree_filepaths, taxa_filepath, is_rooted=is_rooted, burnin=0)
            taxon_set = paup_sd.taxon_set
            dp_sd = treesplit.SplitDistribution(taxon_set=taxon_set)
            dp_sd.ignore_edge_lengths = True
            dp_sd.ignore_node_ages = True
            dp_sd.is_rooted = is_rooted

            _LOG.debug("Taxon set: %s" % [t.label for t in taxon_set])
            taxa_mask = taxon_set.all_taxa_bitmask()
            taxon_set.lock()
            for tree_filepath in tree_filepaths:
                for tree in dataio.tree_source_iter(
                    stream=open(tree_filepath, "rU"), schema="nexus", taxon_set=taxon_set, as_rooted=is_rooted
                ):
                    self.assertIs(tree.taxon_set, dp_sd.taxon_set)
                    self.assertIs(tree.taxon_set, taxon_set)
                    treesplit.encode_splits(tree)
                    dp_sd.count_splits_on_tree(tree)

            self.assertEqual(dp_sd.total_trees_counted, paup_sd.total_trees_counted)

            # SplitsDistribution counts trivial splits, whereas PAUP*
            # contree does not, so the following will not work
            #            assert len(dp_sd.splits) == len(paup_sd.splits),\
            #                 "dp = %d, sd = %d" % (len(dp_sd.splits), len(paup_sd.splits))

            taxa_mask = taxon_set.all_taxa_bitmask()
            for split in dp_sd.splits:
                if not treesplit.is_trivial_split(split, taxa_mask):
                    self.assertIn(split, paup_sd.splits)
                    self.assertEqual(dp_sd.split_counts[split], paup_sd.split_counts[split])
                    paup_sd.splits.remove(split)

            # if any splits remain, they were not
            # in dp_sd or were trivial
            remaining_splits = list(paup_sd.splits)
            for split in remaining_splits:
                if treesplit.is_trivial_split(split, taxa_mask):
                    paup_sd.splits.remove(split)
            self.assertEqual(len(paup_sd.splits), 0)
 def runTest(self):
     y = True
     n = False
     for i, r in enumerate([
             y,
             y,
             y,
             n,
             y,
             n,
             n,
             y,
             y,
             n,
             n,
             y,
             n,
             y,
             y,
             y,
             y,
             y,
             y,
             n,
             y,
             n,
             n,
             y,
             y,
             n,
             n,
             y,
             n,
             y,
             y,
             y,
     ]):
         self.assertEqual(r, treesplit.is_trivial_split(i, 0xF))
     for i, r in enumerate([
             y,
             y,
             y,
             n,
             y,
             n,
             n,
             n,
             y,
             n,
             n,
             n,
             n,
             n,
             n,
             y,
             y,
             n,
             n,
             n,
             n,
             n,
             n,
             y,
             n,
             n,
             n,
             y,
             n,
             y,
             y,
             y,
     ]):
         self.assertEqual(r, treesplit.is_trivial_split(i, 0x1F))
         #0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5  6  7  8  9  0  1
     for i, r in enumerate([
             y,
             y,
             y,
             n,
             y,
             n,
             n,
             y,
             y,
             y,
             y,
             n,
             y,
             n,
             n,
             y,
             y,
             n,
             n,
             y,
             n,
             y,
             y,
             y,
             y,
             n,
             n,
             y,
             n,
             y,
             y,
             y,
     ]):
         self.assertEqual(r, treesplit.is_trivial_split(i, 0x17))