예제 #1
0
 def test_upgrade_provenance(self):
     ts = msprime.simulate(10)
     for record_text in old_provenance_examples:
         record = json.loads(record_text)
         prov = msprime.Provenance(timestamp='2018-08-25T14:59:13',
                                   record=json.dumps(record))
         is_slim, version = pyslim.slim_provenance_version(prov)
         self.assertTrue(is_slim)
         if 'file_version' in record:
             self.assertEqual(version, "0.1")
         else:
             self.assertEqual(version, record['slim']['file_version'])
         tables = ts.dump_tables()
         tables.provenances.add_row(json.dumps(record))
         pyslim.upgrade_slim_provenance(tables)  # modifies the tables
         new_ts = tables.tree_sequence()
         self.assertEqual(new_ts.num_provenances, 3)
         is_slim, version = pyslim.slim_provenance_version(
             new_ts.provenance(2))
         self.assertTrue(is_slim)
         self.assertEqual(version, "0.4")
         new_record = json.loads(new_ts.provenance(2).record)
         if 'model_type' in record:
             self.assertEqual(record['model_type'],
                              new_record['parameters']['model_type'])
             self.assertEqual(record['generation'],
                              new_record['slim']["generation"])
         else:
             self.assertEqual(record['parameters']['model_type'],
                              new_record['parameters']['model_type'])
             self.assertEqual(record['slim']['generation'],
                              new_record['slim']["generation"])
예제 #2
0
 def test_upgrade_provenance(self):
     ts = msprime.sim_ancestry(10)
     for record_text in old_provenance_examples:
         record = json.loads(record_text)
         prov = tskit.Provenance(id=0,
                                 timestamp='2018-08-25T14:59:13',
                                 record=json.dumps(record))
         is_slim, version = pyslim.slim_provenance_version(prov)
         assert is_slim
         if 'file_version' in record:
             assert version == "0.1"
         else:
             assert version == record['slim']['file_version']
         tables = ts.dump_tables()
         tables.provenances.add_row(json.dumps(record))
         pyslim.upgrade_slim_provenance(tables)  # modifies the tables
         new_ts = tables.tree_sequence()
         assert new_ts.num_provenances == 3
         is_slim, version = pyslim.slim_provenance_version(
             new_ts.provenance(2))
         assert is_slim
         assert version == "0.4"
         new_record = json.loads(new_ts.provenance(2).record)
         if 'model_type' in record:
             assert record['model_type'] == new_record['parameters'][
                 'model_type']
             assert record['generation'] == new_record['slim']["generation"]
         else:
             assert record['parameters']['model_type'] == new_record[
                 'parameters']['model_type']
             assert record['slim']['generation'] == new_record['slim'][
                 "generation"]
예제 #3
0
 def test_get_all_provenances(self):
     for ts in self.get_slim_examples(WF=True):
         rts = self.run_msprime_restart(ts)
         provenances = rts.slim_provenances
         self.assertEqual(len(provenances), 2)
         self.assertEqual(ts.slim_provenance, provenances[0])
         # mrts = pyslim.SlimTreeSequence(msprime.mutate(rts, rate=0.001))
         j = 0
         for p in rts.provenances():
             is_slim, _ = pyslim.slim_provenance_version(p)
             if is_slim:
                 sp = pyslim.parse_provenance(p)
                 self.assertEqual(provenances[j], sp)
                 j += 1
             else:
                 with self.assertRaises(ValueError):
                     pyslim.parse_provenance(p)
예제 #4
0
 def test_get_all_provenances(self, recipe, helper_functions, tmp_path):
     ts = recipe["ts"]
     rts = helper_functions.run_msprime_restart(ts, tmp_path, WF=True)
     provenances = rts.slim_provenances
     assert len(provenances) == 2
     with pytest.warns(Warning):
         last_prov = ts.slim_provenance
     assert last_prov == provenances[0]
     # mrts = pyslim.SlimTreeSequence(msprime.mutate(rts, rate=0.001))
     j = 0
     for p in rts.provenances():
         is_slim, _ = pyslim.slim_provenance_version(p)
         if is_slim:
             sp = pyslim.parse_provenance(p)
             assert provenances[j] == sp
             j += 1
         else:
             with pytest.raises(ValueError):
                 pyslim.parse_provenance(p)