Пример #1
0
def MutsFromTrees(Trees):

    print('read trees')

    ts = pyslim.load(Trees).simplify()

    variants = []
    #	for  variant in pyslim.extract_mutation_metadata(ts.tables):
    #		print(variant)
    #	return

    for variant, mut, node in zip(ts.variants(),
                                  pyslim.extract_mutation_metadata(ts.tables),
                                  pyslim.extract_node_metadata(ts.tables)):

        #		print ()
        #		print (variant)
        #		print (mut)
        #		print (node)

        freq = sum(variant.genotypes) / len(variant.genotypes)
        #		print (freq)

        if freq >= 1: continue
        if len(mut) > 1: pass
        variants.append([variant.site.position, freq, mut[0].selection_coeff])

    return variants
Пример #2
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])
Пример #3
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)
Пример #4
0
 def verify_defaults(self, ts):
     '''
     Verify the default values have been entered into metadata.
     '''
     mut_md = pyslim.extract_mutation_metadata(ts.tables)
     for md in mut_md:
         self.assertEqual(md.mutation_type, 1)
         self.assertEqual(md.selection_coeff, 0.0)
         self.assertEqual(md.population, tskit.NULL)
         self.assertEqual(md.slim_time, 0)
     node_md = pyslim.extract_node_metadata(ts.tables)
     for md, node in zip(node_md, ts.nodes()):
         if not node.is_sample():
             self.assertEqual(md, None)
         else:
             self.assertEqual(md.is_null, False)
             self.assertEqual(md.genome_type, pyslim.GENOME_TYPE_AUTOSOME)
     for ind in ts.individuals():
         self.assertArrayEqual(ind.location, [0, 0, 0])
         self.assertEqual(ind.flags, pyslim.INDIVIDUAL_ALIVE)
     ind_md = pyslim.extract_individual_metadata(ts.tables)
     for md in ind_md:
         self.assertEqual(md.sex, pyslim.INDIVIDUAL_TYPE_HERMAPHRODITE)
         self.assertEqual(md.flags, 0)
     pop_md = pyslim.extract_population_metadata(ts.tables)
     for md in pop_md:
         self.assertEqual(md.selfing_fraction, 0.0)
         self.assertEqual(md.female_cloning_fraction, 0.0)
         self.assertEqual(md.male_cloning_fraction, 0.0)
         self.assertEqual(md.sex_ratio, 0.5)
         self.assertEqual(md.bounds_x0, 0.0)
         self.assertEqual(md.bounds_x1, 0.0)
         self.assertEqual(md.bounds_y0, 0.0)
         self.assertEqual(md.bounds_y1, 0.0)
         self.assertEqual(md.bounds_z0, 0.0)
         self.assertEqual(md.bounds_z1, 0.0)
         self.assertEqual(len(md.migration_records), 0)