예제 #1
0
 def verify_round_trip(self, ts, version):
     msprime.dump_legacy(ts, self.temp_file, version=version)
     with silence_stderr():
         tsp = msprime.load_legacy(self.temp_file)
     self.verify_tree_sequences_equal(ts, tsp)
     tsp.dump(self.temp_file)
     tsp = msprime.load(self.temp_file)
     self.verify_tree_sequences_equal(ts, tsp)
예제 #2
0
 def test_v2_no_samples(self):
     ts = multi_locus_with_mutation_example()
     msprime.dump_legacy(ts, self.temp_file, version=2)
     root = h5py.File(self.temp_file, "r+")
     del root['samples']
     root.close()
     tsp = msprime.load_legacy(self.temp_file)
     self.verify_tree_sequences_equal(ts, tsp)
예제 #3
0
 def verify_round_trip(self, ts, version):
     msprime.dump_legacy(ts, self.temp_file, version=version)
     tsp = msprime.load_legacy(self.temp_file)
     simplify = version < 10
     self.verify_tree_sequences_equal(ts, tsp, simplify=simplify)
     tsp.dump(self.temp_file)
     tsp = msprime.load(self.temp_file)
     self.verify_tree_sequences_equal(ts, tsp, simplify=simplify)
예제 #4
0
 def verify_malformed_json_v2(self, ts, group_name, attr, bad_json):
     msprime.dump_legacy(ts, self.temp_file, 2)
     # Write some bad JSON to the provenance string.
     root = h5py.File(self.temp_file, "r+")
     group = root[group_name]
     group.attrs[attr] = bad_json
     root.close()
     tsp = msprime.load_legacy(self.temp_file)
     self.verify_tree_sequences_equal(ts, tsp)
예제 #5
0
def run_upgrade(args):
    try:
        tree_sequence = msprime.load_legacy(args.source,
                                            args.remove_duplicate_positions)
    except msprime.DuplicatePositionsError:
        exit(
            "Error: Duplicate mutation positions in the source file detected.\n\n"
            "This is not supported in the current file format. Running \"upgrade -d\" "
            "will remove these duplicate positions. However, this will result in loss "
            "of data from the original file!")
    tree_sequence.dump(args.destination)
예제 #6
0
 def test_duplicate_mutation_positions_single_value(self):
     ts = multi_locus_with_mutation_example()
     for version in [2, 3]:
         msprime.dump_legacy(ts, self.temp_file, version=version)
         root = h5py.File(self.temp_file, "r+")
         root['mutations/position'][:] = 0
         root.close()
         self.assertRaises(msprime.DuplicatePositionsError,
                           msprime.load_legacy, self.temp_file)
         tsp = msprime.load_legacy(self.temp_file,
                                   remove_duplicate_positions=True)
         self.assertEqual(tsp.num_sites, 1)
         sites = list(tsp.sites())
         self.assertEqual(sites[0].position, 0)
예제 #7
0
 def test_duplicate_mutation_positions(self):
     ts = multi_locus_with_mutation_example()
     for version in [2, 3]:
         msprime.dump_legacy(ts, self.temp_file, version=version)
         root = h5py.File(self.temp_file, "r+")
         position = np.array(root['mutations/position'])
         position[0] = position[1]
         root['mutations/position'][:] = position
         root.close()
         self.assertRaises(msprime.DuplicatePositionsError,
                           msprime.load_legacy, self.temp_file)
         tsp = msprime.load_legacy(self.temp_file,
                                   remove_duplicate_positions=True)
         self.assertEqual(tsp.num_sites, position.shape[0] - 1)
         position_after = list(s.position for s in tsp.sites())
         self.assertEqual(list(position[1:]), position_after)
예제 #8
0
 def verify_round_trip(self, ts):
     with tempfile.NamedTemporaryFile(prefix="msp_ff_") as f:
         tmp = sys.stderr
         try:
             with open("/dev/null", "w") as devnull:
                 sys.stderr = devnull
                 # We silence stderr here because h5py dumps out some
                 # spurious # error messages. See
                 # https://github.com/h5py/h5py/issues/390
                 msprime.dump_legacy(ts, f.name)
                 tsp = msprime.load_legacy(f.name)
         finally:
             sys.stderr = tmp
     self.assertEqual(ts.get_num_records(), tsp.get_num_records())
     self.assertEqual(ts.get_sample_size(), tsp.get_sample_size())
     self.assertEqual(ts.get_sequence_length(), tsp.get_sequence_length())
     self.assertEqual(ts.get_num_mutations(), tsp.get_num_mutations())
     j = 0
     for r1, r2 in zip(ts.records(), tsp.records()):
         self.assertEqual(r1.left, r2.left)
         self.assertEqual(r1.right, r2.right)
         self.assertEqual(r1.node, r2.node)
         self.assertEqual(r1.time, r2.time)
         self.assertEqual(r1.children, r2.children)
         self.assertEqual(r1.population, r2.population)
         j += 1
     self.assertEqual(j, ts.get_num_records())
     self.assertEqual(ts.get_num_trees(), tsp.get_num_trees())
     j = 0
     for m1, m2 in zip(ts.mutations(), tsp.mutations()):
         self.assertEqual(m1.position, m2.position)
         self.assertEqual(m1.node, m2.node)
         j += 1
     self.assertEqual(ts.get_num_nodes(), tsp.get_num_nodes())
     for u in range(ts.get_sample_size()):
         self.assertEqual(ts.get_population(u), tsp.get_population(u))
     provenance = tsp.get_provenance()
     if ts.get_num_mutations() > 0:
         self.assertEqual(len(provenance), 3)
     else:
         self.assertEqual(len(provenance), 2)
     for p in provenance:
         self.assertIsInstance(json.loads(p), dict)
예제 #9
0
 def verify_round_trip(self, ts):
     with tempfile.NamedTemporaryFile(prefix="msp_ff_") as f:
         tmp = sys.stderr
         try:
             with open("/dev/null", "w") as devnull:
                 sys.stderr = devnull
                 # We silence stderr here because h5py dumps out some
                 # spurious # error messages. See
                 # https://github.com/h5py/h5py/issues/390
                 msprime.dump_legacy(ts, f.name)
                 tsp = msprime.load_legacy(f.name)
         finally:
             sys.stderr = tmp
     self.assertEqual(ts.get_num_records(), tsp.get_num_records())
     self.assertEqual(ts.get_sample_size(), tsp.get_sample_size())
     self.assertEqual(ts.get_sequence_length(), tsp.get_sequence_length())
     self.assertEqual(ts.get_num_mutations(), tsp.get_num_mutations())
     j = 0
     for r1, r2 in zip(ts.records(), tsp.records()):
         self.assertEqual(r1.left, r2.left)
         self.assertEqual(r1.right, r2.right)
         self.assertEqual(r1.node, r2.node)
         self.assertEqual(r1.time, r2.time)
         self.assertEqual(r1.children, r2.children)
         self.assertEqual(r1.population, r2.population)
         j += 1
     self.assertEqual(j, ts.get_num_records())
     self.assertEqual(ts.get_num_trees(), tsp.get_num_trees())
     j = 0
     for m1, m2 in zip(ts.mutations(), tsp.mutations()):
         self.assertEqual(m1.position, m2.position)
         self.assertEqual(m1.node, m2.node)
         j += 1
     self.assertEqual(ts.get_num_nodes(), tsp.get_num_nodes())
     for u in range(ts.get_sample_size()):
         self.assertEqual(ts.get_population(u), tsp.get_population(u))
     provenance = tsp.get_provenance()
     if ts.get_num_mutations() > 0:
         self.assertEqual(len(provenance), 3)
     else:
         self.assertEqual(len(provenance), 2)
     for p in provenance:
         self.assertIsInstance(json.loads(p), dict)
예제 #10
0
def run_upgrade(args):
    tree_sequence = msprime.load_legacy(args.source)
    tree_sequence.dump(args.destination)
예제 #11
0
 def test_msprime_v_0_3_0(self):
     ts = msprime.load_legacy(
         "tests/data/hdf5-formats/msprime-0.3.0_v2.0.hdf5")
     self.verify_tree_sequence(ts)
예제 #12
0
파일: cli.py 프로젝트: td329/msprime
def run_upgrade(args):
    tree_sequence = msprime.load_legacy(args.source)
    tree_sequence.dump(args.destination)