Пример #1
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)
Пример #2
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)
Пример #3
0
 def test_annotate_nodes(self):
     for ts in get_msprime_examples():
         slim_ts = pyslim.annotate_defaults(ts, model_type="nonWF", slim_generation=1)
         tables = slim_ts.tables
         metadata = list(pyslim.extract_node_metadata(tables))
         self.assertEqual(len(metadata), slim_ts.num_nodes)
         gtypes = [random.choice([pyslim.GENOME_TYPE_X, pyslim.GENOME_TYPE_Y])
                   for _ in metadata]
         for j in range(len(metadata)):
             if metadata[j] is not None:
                 metadata[j].genome_type = gtypes[j]
         pyslim.annotate_node_metadata(tables, metadata)
         new_ts = pyslim.load_tables(tables)
         for j, x in enumerate(new_ts.nodes()):
             md = pyslim.decode_node(x.metadata)
             if md is not None:
                 self.assertEqual(md.genome_type, gtypes[j])
Пример #4
0
 def test_annotate_XY(self):
     for ts in self.get_msprime_examples():
         for genome_type in ["X", "Y"]:
             slim_ts = pyslim.annotate_defaults(ts,
                                                model_type="nonWF",
                                                slim_generation=1)
             tables = slim_ts.tables
             metadata = list(pyslim.extract_individual_metadata(tables))
             self.assertEqual(len(metadata), slim_ts.num_individuals)
             sexes = [
                 random.choice([
                     pyslim.INDIVIDUAL_TYPE_FEMALE,
                     pyslim.INDIVIDUAL_TYPE_MALE
                 ]) for _ in metadata
             ]
             for j in range(len(metadata)):
                 metadata[j].sex = sexes[j]
             pyslim.annotate_individual_metadata(tables, metadata)
             node_metadata = list(pyslim.extract_node_metadata(tables))
             self.assertEqual(len(node_metadata), slim_ts.num_nodes)
             for j in range(slim_ts.num_individuals):
                 nodes = slim_ts.individual(j).nodes
                 node_metadata[nodes[0]].genome_type = pyslim.GENOME_TYPE_X
                 node_metadata[nodes[0]].is_null = (genome_type != "X")
                 if sexes[j] == pyslim.INDIVIDUAL_TYPE_MALE:
                     node_metadata[
                         nodes[1]].genome_type = pyslim.GENOME_TYPE_Y
                     node_metadata[nodes[1]].is_null = (genome_type != "Y")
                 else:
                     node_metadata[
                         nodes[1]].genome_type = pyslim.GENOME_TYPE_X
                     node_metadata[nodes[1]].is_null = (genome_type != "X")
             pyslim.annotate_node_metadata(tables, node_metadata)
             new_ts = pyslim.load_tables(tables)
             # try loading this into SLiM
             loaded_ts = self.run_msprime_restart(new_ts, sex=genome_type)
             self.verify_annotated_tables(new_ts, slim_ts)
             self.verify_annotated_trees(new_ts, slim_ts)
             self.verify_haplotype_equality(new_ts, slim_ts)