Exemplo n.º 1
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'))
Exemplo n.º 2
0
 def test_population_metadata(self):
     mrs = [pyslim.PopulationMigrationMetadata(source_subpop=j, migration_rate=0.2)
            for j in range(3)]
     for mr_list in [[], mrs]:
         md = pyslim.PopulationMetadata(
                 slim_id=1, selfing_fraction=0.75, female_cloning_fraction=0.2,
                 male_cloning_fraction=0.8, sex_ratio=0.6, bounds_x0=-1.0,
                 bounds_x1=2.0, bounds_y0=0.0, bounds_y1=0.0, bounds_z0=0.0,
                 bounds_z1=1.0, migration_records=mr_list)
         md_bytes = pyslim.encode_population(md)
         new_md = pyslim.decode_population(md_bytes)
         self.assertEqual(md, new_md)
Exemplo n.º 3
0
    def test_annotate_populations(self):
        for ts in self.get_slim_examples():
            tables = ts.tables
            new_tables = ts.tables
            metadata = []
            for md in tskit.unpack_bytes(tables.populations.metadata,
                                         tables.populations.metadata_offset):
                dm = pyslim.decode_population(md)
                edm = pyslim.encode_population(dm)
                self.assertEqual(md, edm)
                metadata.append(dm)

            pyslim.annotate_population_metadata(new_tables, metadata)
            self.assertEqual(tables, new_tables)
Exemplo n.º 4
0
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)

pyslim.annotate_individuals(tables, individual_metadata)

# populations

population_metadata = []
for md in msprime.unpack_bytes(tables.populations.metadata,
                               tables.populations.metadata_offset):
    if len(md) > 0:
        dp = pyslim.decode_population(md)
        edp = pyslim.encode_population(dp)
        assert (md == edp)
    else:
        dp = None
    population_metadata.append(dp)

pyslim.annotate_populations(tables, population_metadata)

print(tables)