Skip to content

Commit

Permalink
get rid of subpop haplosome vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Oct 6, 2024
1 parent eb4dfd0 commit 720ea99
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 384 deletions.
10 changes: 5 additions & 5 deletions SLiMgui/GraphView_MutationFrequencyTrajectory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,11 @@ - (void)fetchDataForFinishedTick
{
Subpopulation *subpop = subpop_pair.second;

slim_popsize_t subpop_haplosome_count = 2 * subpop->parent_subpop_size_;
std::vector<Haplosome *> &subpop_haplosome = subpop->parent_haplosomes_;

for (int i = 0; i < subpop_haplosome_count; i++)
for (Individual *ind : subpop->parent_individuals_)
{
for (int haplosome_index = 0; haplosome_index <= 1; ++haplosome_index)
{
Haplosome &haplosome = *subpop_haplosome[i];
Haplosome &haplosome = *((haplosome_index == 0) ? ind->haplosome1_ : ind->haplosome2_);

if (!haplosome.IsNull())
{
Expand All @@ -345,6 +344,7 @@ - (void)fetchDataForFinishedTick
subpop_total_haplosome_count++;
}
}
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion SLiMgui/SLiMHaplotypeManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,20 @@ - (instancetype)initWithClusteringMethod:(SLiMHaplotypeClusteringMethod)clusteri
[self setSubpopCount:(int)selected_subpops.size()];

// Fetch haplosomes and figure out what we're going to plot; note that we plot only non-null haplosomes
#warning we need a focal chromosome here; we can't align non-homologous haplosomes
for (Subpopulation *subpop : selected_subpops)
for (Haplosome *haplosome : subpop->parent_haplosomes_)
{
for (Individual *ind : subpop->parent_individuals_)
{
for (int haplosome_index = 0; haplosome_index <= 1; ++haplosome_index)
{
Haplosome *haplosome = ((haplosome_index == 0) ? ind->haplosome1_ : ind->haplosome2_);

if (!haplosome->IsNull())
haplosomes.emplace_back(haplosome);
}
}
}

// If a sample is requested, select that now; sampleSize <= 0 means no sampling
if ((sampleSize > 0) && ((int)haplosomes.size() > sampleSize))
Expand Down
26 changes: 24 additions & 2 deletions core/haplosome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4138,8 +4138,19 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_removeMutations(EidosGlobalStringID
{
// Mark all non-null haplosomes in the simulation that are not among the target haplosomes
for (auto subpop_pair : species->population_.subpops_)
for (Haplosome *haplosome : subpop_pair.second->parent_haplosomes_)
{
Subpopulation *subpop = subpop_pair.second;

for (Individual *ind : subpop->parent_individuals_)
{
for (int haplosome_index = 0; haplosome_index <= 1; ++haplosome_index)
{
Haplosome *haplosome = ((haplosome_index == 0) ? ind->haplosome1_ : ind->haplosome2_);

haplosome->scratch_ = (haplosome->IsNull() ? 0 : 1);
}
}
}

for (int haplosome_index = 0; haplosome_index < target_size; ++haplosome_index)
targets_data[haplosome_index]->scratch_ = 0;
Expand All @@ -4161,13 +4172,24 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_removeMutations(EidosGlobalStringID

// Loop through those haplosomes and log the new derived state at each (unique) position
for (auto subpop_pair : species->population_.subpops_)
for (Haplosome *haplosome : subpop_pair.second->parent_haplosomes_)
{
Subpopulation *subpop = subpop_pair.second;

for (Individual *ind : subpop->parent_individuals_)
{
for (int haplosome_index = 0; haplosome_index <= 1; ++haplosome_index)
{
Haplosome *haplosome = ((haplosome_index == 0) ? ind->haplosome1_ : ind->haplosome2_);

if (haplosome->scratch_ == 1)
{
for (slim_position_t position : unique_positions)
species->RecordNewDerivedState(haplosome, position, *haplosome->derived_mutation_ids_at_position(position));
haplosome->scratch_ = 0;
}
}
}
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions core/individual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ Individual::Individual(Subpopulation *p_subpopulation, slim_popsize_t p_individu
#endif
}

Individual::~Individual(void)
{
// BCH 10/6/2024: Individual now owns the haplosomes inside it (a policy change for multichrom)
// This means the subpopulation_ pointer must be valid at this point!
subpopulation_->FreeSubpopHaplosome(haplosome1_);
subpopulation_->FreeSubpopHaplosome(haplosome2_);
}

static inline bool _InPedigree(slim_pedigreeid_t A, slim_pedigreeid_t A_P1, slim_pedigreeid_t A_P2, slim_pedigreeid_t A_G1, slim_pedigreeid_t A_G2, slim_pedigreeid_t A_G3, slim_pedigreeid_t A_G4, slim_pedigreeid_t B)
{
if (B == -1)
Expand Down
4 changes: 2 additions & 2 deletions core/individual.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Individual : public EidosDictionaryUnretained
// that confuses interpretation; note that individual_cached_fitness_OVERRIDE_ is not relevant to this
#endif

Haplosome *haplosome1_, *haplosome2_; // NOT OWNED; must correspond to the entries in the Subpopulation we live in
Haplosome *haplosome1_, *haplosome2_; // OWNED; must correspond to the entries in the Subpopulation we live in
slim_age_t age_; // nonWF only: the age of the individual, in cycles; -1 in WF models

slim_popsize_t index_; // the individual index in that subpop (0-based, and not multiplied by 2)
Expand All @@ -150,7 +150,7 @@ class Individual : public EidosDictionaryUnretained
Individual& operator= (const Individual &p_original) = delete; // no copy construction
Individual(void) = delete; // no null construction
Individual(Subpopulation *p_subpopulation, slim_popsize_t p_individual_index, Haplosome *p_haplosome1, Haplosome *p_haplosome2, IndividualSex p_sex, slim_age_t p_age, double p_fitness, float p_mean_parent_age);
inline virtual ~Individual(void) override { }
virtual ~Individual(void) override;

inline __attribute__((always_inline)) void ClearColor(void) { color_set_ = false; }

Expand Down
Loading

0 comments on commit 720ea99

Please sign in to comment.