Skip to content

Commit 051b47d

Browse files
committed
fix #642, unreferenced mutation from multiple reload
1 parent 3b66ac3 commit 051b47d

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

VERSIONS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ multitrait branch:
185185
(float$)calcVA(object<Individual> individuals, [Nio<MutationType>$ mutType = NULL], [Niso<Trait>$ trait = NULL]): additive genetic variance
186186
(float$)calcVD(object<Individual> individuals, [Nio<MutationType>$ mutType = NULL], [Niso<Trait>$ trait = NULL]): dominance genetic variance
187187
(float$)calcVG(object<Individual> individuals, [Nio<MutationType>$ mutType = NULL], [Niso<Trait>$ trait = NULL]): total genetic variance
188-
fix #641, a crash related to expanding the mutation block buffers when reading in from a file (whether .trees, VCF, MS, or SLiM format), or inside addNew[Drawn]Mutation()
188+
fix #641, a crash related to expanding the mutation block buffers when reading in from a file (whether .trees, VCF, MS, or SLiM format), or inside addNew[Drawn]Mutation() (new in multitrait)
189+
fix #642, mutations retained by the tree not re-retained by the tree when a saved tree sequence file is reloaded (new in multitrait)
189190

190191

191192
version 5.2 (Eidos version 4.2):

core/species.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12897,11 +12897,6 @@ void Species::__CreateMutationsFromTabulation(std::unordered_map<slim_mutationid
1289712897
if (gSLiM_next_mutation_id <= mutation_id)
1289812898
gSLiM_next_mutation_id = mutation_id + 1;
1289912899

12900-
// a mutation might not be referenced by any extant haplosome; it might be present in an ancestral node,
12901-
// but have been lost in all descendants, in which case we do not need to instantiate it
12902-
if (mut_info.ref_count == 0)
12903-
continue;
12904-
1290512900
#if DEBUG
1290612901
// BCH 2/13/2026: We used to do a memcpy() here to give us an aligned copy of metadata_ptr, but in the
1290712902
// new metadata design the pointer should always be to an aligned address; we error here if not
@@ -12943,14 +12938,34 @@ void Species::__CreateMutationsFromTabulation(std::unordered_map<slim_mutationid
1294312938

1294412939
Mutation *new_mut = new (mut_block_ptr + new_mut_index) Mutation(mutation_id, mutation_type_ptr, chromosome_index, position, metadata_ptr);
1294512940

12946-
// add it to our local map, so we can find it when making haplosomes, and to the population's mutation registry
12947-
p_mutIndexMap[mutation_id] = new_mut_index;
12948-
population_.MutationRegistryAdd(new_mut, /* p_autogenerated */ false);
12949-
12941+
// a mutation might not be referenced by any extant haplosome; it might be present in an ancestral node,
12942+
// but have been lost in all descendants, in which case we do not need to instantiate it
12943+
// BCH 7/16/2026: Now we DO instantiate such mutations; they are "retained by the tree",
12944+
// since they are referenced by an ancestral derived state somewhere in the tree sequence
12945+
if (mut_info.ref_count == 0)
12946+
{
12947+
// it is legal to read a .trees file in without tree-seq mutations enabled; in that case,
12948+
// there is no such thing as "retained by the tree" so we can just ignore these mutations
12949+
if (RecordingTreeSequenceMutations())
12950+
{
12951+
muts_retained_by_treeseq_.push_back(new_mut_index);
12952+
any_muts_retained_impermanently_ = true; // we don't know here, so we assume true
12953+
12954+
//new_mut->Retain(); // new mutations already have a retain count of 1; we take that over here, as MutationRegistryAdd() does
12955+
new_mut->retained_by_treeseq_ = true;
12956+
}
12957+
}
12958+
else
12959+
{
12960+
// add it to our local map, so we can find it when making haplosomes, and to the population's mutation registry
12961+
p_mutIndexMap[mutation_id] = new_mut_index;
12962+
population_.MutationRegistryAdd(new_mut, /* p_autogenerated */ false);
12963+
1295012964
#ifdef SLIM_KEEP_MUTTYPE_REGISTRIES
12951-
if (population_.keeping_muttype_registries_)
12952-
EIDOS_TERMINATION << "ERROR (Species::__CreateMutationsFromTabulation): (internal error) separate muttype registries set up during pop load." << EidosTerminate();
12965+
if (population_.keeping_muttype_registries_)
12966+
EIDOS_TERMINATION << "ERROR (Species::__CreateMutationsFromTabulation): (internal error) separate muttype registries set up during pop load." << EidosTerminate();
1295312967
#endif
12968+
}
1295412969
}
1295512970
}
1295612971
}

0 commit comments

Comments
 (0)