def test_count_other_values_two(self): expected = { 'Harry': 1, 'Simon': 2, 'Peter': 1, 'Betty': 0, 'Louise': 0 } nexus = NexusReader() nexus.read_string("""#NEXUS Begin data; Dimensions ntax=5 nchar=3; Format datatype=standard symbols="01" gap=-; Matrix Harry 0A0 [No missing] Simon 0AB [one missing] Peter 0-B [one gap] Betty ?-1 [one gap and one missing = 2 missing] Louise ??? [three missing] ; End; """) count = count_site_values(nexus, ['A', 'B']) for taxon in count: assert count[taxon] == expected[taxon]
def print_site_values(nexus_obj, characters=['-', '?']): """ Prints out counts of the number of sites with state in `characters` in a nexus. (Wrapper around `count_site_values`) :param nexus_obj: A `NexusReader` instance :type nexus_obj: NexusReader """ count = count_site_values(nexus_obj, characters) print ("Number of %s in %s" % (",".join(characters), nexus_obj.filename)) for taxon in sorted(count): prop = (count[taxon] / nexus.data.nchar) * 100 print( "%s: %d/%d (%0.2f%%)" % (taxon.ljust(20), count[taxon], nexus.data.nchar, prop) ) print('-' * 76) total_count = sum([x for x in count.values()]) total_data = nexus.data.nchar * nexus.data.ntaxa prop = (total_count / total_data) * 100 print('TOTAL: %d/%d (%0.2f%%)' % (total_count, total_data, prop) )
def print_site_values(nexus_obj, characters=None): """ Prints out counts of the number of sites with state in `characters` in a nexus. (Wrapper around `count_site_values`) :param nexus_obj: A `NexusReader` instance :type nexus_obj: NexusReader """ characters = characters if characters is not None else ['-', '?'] count = count_site_values(nexus_obj, characters) print("Number of %s in %s" % (",".join(characters), nexus_obj.filename)) for taxon in sorted(count): prop = (count[taxon] / nexus.data.nchar) * 100 print( "%s: %d/%d (%0.2f%%)" % (taxon.ljust(20), count[taxon], nexus.data.nchar, prop) ) print('-' * 76) total_count = sum([x for x in count.values()]) total_data = nexus.data.nchar * nexus.data.ntaxa prop = (total_count / total_data) * 100 print('TOTAL: %d/%d (%0.2f%%)' % (total_count, total_data, prop) )
def test_count_missing_two(): expected = {'Harry': 0, 'Simon': 1, 'Peter': 1, 'Betty': 2, 'Louise': 3} nexus = NexusReader.from_string("""#NEXUS Begin data; Dimensions ntax=5 nchar=3; Format datatype=standard symbols="01" gap=-; Matrix Harry 010 [No missing] Simon 0?0 [one missing] Peter 0-0 [one gap] Betty ?-1 [one gap and one missing = 2 missing] Louise ??? [three missing] ; End; """) missing = count_site_values(nexus) for taxon in missing: assert missing[taxon] == expected[taxon]
def test_count_other_values_two(self): expected = {"Harry": 1, "Simon": 2, "Peter": 1, "Betty": 0, "Louise": 0} nexus = NexusReader() nexus.read_string( """#NEXUS Begin data; Dimensions ntax=5 nchar=3; Format datatype=standard symbols="01" gap=-; Matrix Harry 0A0 [No missing] Simon 0AB [one missing] Peter 0-B [one gap] Betty ?-1 [one gap and one missing = 2 missing] Louise ??? [three missing] ; End; """ ) count = count_site_values(nexus, ["A", "B"]) for taxon in count: assert count[taxon] == expected[taxon]
def test_count_other_values_one(self): expected = { 'Harry': 1, 'Simon': 1, 'Peter': 0, 'Betty': 0, 'Louise': 0 } nexus = NexusReader() nexus.read_string("""#NEXUS Begin data; Dimensions ntax=5 nchar=3; Format datatype=standard symbols="01" gap=-; Matrix Harry 0A0 [No missing] Simon 0A0 [one missing] Peter 0-0 [one gap] Betty ?-1 [one gap and one missing = 2 missing] Louise ??? [three missing] ; End; """) count = count_site_values(nexus, 'A') for taxon in count: assert count[taxon] == expected[taxon]
def test_count_missing_one(self): nexus = NexusReader(os.path.join(EXAMPLE_DIR, "example.nex")) missing = count_site_values(nexus) for taxon in missing: assert missing[taxon] == 0
def test_count_missing_one(self): nexus = NexusReader(os.path.join(EXAMPLE_DIR, 'example.nex')) missing = count_site_values(nexus) for taxon in missing: assert missing[taxon] == 0
def test_errorcheck_characters(nex): with pytest.raises(TypeError): count_site_values(nex, None)
def test_count_missing_one(nex): missing = count_site_values(nex) for taxon in missing: assert missing[taxon] == 0