Repository: tskit-dev/pyslim

Issue:
deal appropriately when annotating with existing mutations
We should probably warn when doing `annotate_defaults` if mutations already have metadata.

Discussion:

Patch:
diff --git a/.gitignore b/.gitignore
index e4be91c..1d4e8f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ dist/
 .DS_Store
 .coverage
 htmlcov
+out.pedigree
diff --git a/pyslim/methods.py b/pyslim/methods.py
index 443efac..b7c328c 100644
--- a/pyslim/methods.py
+++ b/pyslim/methods.py
@@ -722,6 +722,11 @@ def _annotate_sites_mutations(tables):
     columns of the Mutation table. We set slim_time in metadata so that
     - tick = floor(tskit time) + slim_time
     '''
+    if len(tables.mutations.metadata) > 0:
+        warnings.warn(
+                "The provided tree sequence already has some mutations with "
+                "metadata; this metadata will be overwritten."
+        )
     num_mutations = tables.mutations.num_rows
     default_mut = default_slim_metadata("mutation_list_entry")
     dsb, dso = tskit.pack_bytes([str(j).encode() for j in range(num_mutations)])


Test patch:
diff --git a/tests/test_annotation.py b/tests/test_annotation.py
index 1fcf449..bb66d6f 100644
--- a/tests/test_annotation.py
+++ b/tests/test_annotation.py
@@ -233,6 +233,24 @@ class TestAnnotate(tests.PyslimTestCase):
             _ = pyslim.annotate(ts, model_type="WF", tick=1)
         assert "not at integer" in str(except_info)
 
+    def test_warns_overwriting_mutations(self, helper_functions):
+        ts = msprime.sim_ancestry(
+                4,
+                population_size=10,
+                sequence_length=10,
+                recombination_rate=0.01,
+                random_seed=100,
+        )
+        ts = msprime.sim_mutations(
+                ts,
+                rate=1,
+                random_seed=12,
+                model=msprime.SLiMMutationModel(type=1)
+        )
+        assert ts.num_mutations > 0
+        with pytest.warns(Warning, match="already has.*metadata"):
+            slim_ts = pyslim.annotate(ts, model_type="WF", tick=1) 
+
     def test_just_simulate(self, helper_functions, tmp_path):
         ts = msprime.sim_ancestry(
                 4,