Пример #1
0
 def test_node_metadata(self):
     md = pyslim.NodeMetadata(slim_id=2,
                              is_null=False,
                              genome_type=pyslim.GENOME_TYPE_X)
     md_bytes = pyslim.encode_node(md)
     new_md = pyslim.decode_node(md_bytes)
     self.assertEqual(md, new_md)
Пример #2
0
 def test_node_metadata(self):
     md = pyslim.NodeMetadata(slim_id=2,
                              is_null=False,
                              genome_type=pyslim.GENOME_TYPE_X)
     with self.assertWarns(DeprecationWarning):
         md_bytes = pyslim.encode_node(md)
     with self.assertWarns(DeprecationWarning):
         new_md = pyslim.decode_node(md_bytes)
     self.assertEqual(md, new_md)
Пример #3
0
 def test_legacy_errors(self):
     defaults = pyslim.default_slim_metadata
     with self.assertRaisesRegex(ValueError, "legacy"):
         pyslim.decode_mutation(defaults('mutation'))
     with self.assertRaisesRegex(ValueError, "legacy"):
         pyslim.decode_population(defaults('population'))
     with self.assertRaisesRegex(ValueError, "legacy"):
         pyslim.decode_individual(defaults('individual'))
     with self.assertRaisesRegex(ValueError, "legacy"):
         pyslim.decode_node(defaults('node'))
     with self.assertRaisesRegex(ValueError, "legacy"):
         pyslim.encode_mutation(defaults('mutation'))
     with self.assertRaisesRegex(ValueError, "legacy"):
         pyslim.encode_population(defaults('population'))
     with self.assertRaisesRegex(ValueError, "legacy"):
         pyslim.encode_individual(defaults('individual'))
     with self.assertRaisesRegex(ValueError, "legacy"):
         pyslim.encode_node(defaults('node'))
Пример #4
0
    def test_annotate_nodes(self):
        for ts in self.get_slim_examples():
            tables = ts.tables
            new_tables = ts.tables
            metadata = []
            for md in tskit.unpack_bytes(tables.nodes.metadata,
                                         tables.nodes.metadata_offset):
                dm = pyslim.decode_node(md)
                edm = pyslim.encode_node(dm)
                self.assertEqual(md, edm)
                metadata.append(dm)

            pyslim.annotate_node_metadata(new_tables, metadata)
            self.assertEqual(tables, new_tables)
Пример #5
0
    def test_annotate_nodes(self):
        for ts in self.get_slim_examples():
            tables = ts.tables
            new_tables = ts.tables
            metadata = []
            for md in tskit.unpack_bytes(tables.nodes.metadata,
                                         tables.nodes.metadata_offset):
                with self.assertWarns(DeprecationWarning):
                    dm = pyslim.decode_node(md)
                with self.assertWarns(DeprecationWarning):
                    edm = pyslim.encode_node(dm)
                self.assertEqual(md, edm)
                metadata.append(dm)

            with self.assertWarns(DeprecationWarning):
                pyslim.annotate_node_metadata(new_tables, metadata)
            self.assertTableCollectionsEqual(tables, new_tables)
Пример #6
0
for md in msprime.unpack_bytes(tables.mutations.metadata,
                               tables.mutations.metadata_offset):
    dm = pyslim.decode_mutation(md)
    edm = pyslim.encode_mutation(dm)
    assert (md == edm)
    mut_metadata.append(dm)

pyslim.annotate_mutations(tables, mut_metadata)

# nodes

node_metadata = []
for md in msprime.unpack_bytes(tables.nodes.metadata,
                               tables.nodes.metadata_offset):
    dn = pyslim.decode_node(md)
    edn = pyslim.encode_node(dn)
    assert (md == edn)
    node_metadata.append(dn)

pyslim.annotate_nodes(tables, node_metadata)

# individuals

individual_metadata = []
for md in msprime.unpack_bytes(tables.individuals.metadata,
                               tables.individuals.metadata_offset):
    di = pyslim.decode_individual(md)
    edi = pyslim.encode_individual(di)
    assert (md == edi)
    individual_metadata.append(di)