Skip to content

Commit

Permalink
shift to a vector of haplosomes
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Oct 7, 2024
1 parent 720ea99 commit 249ab04
Show file tree
Hide file tree
Showing 14 changed files with 355 additions and 458 deletions.
24 changes: 11 additions & 13 deletions QtSLiM/QtSLiMGraphView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1693,15 +1693,15 @@ void QtSLiMGraphView::contextMenuEvent(QContextMenuEvent *p_event)

void QtSLiMGraphView::setXAxisRangeFromTick(void)
{
Community *community = controller_->community;
Community *community = controller_->community;

// We can't get the estimated last tick until tick ranges are known
if (!community || (community->Tick() < 1))
return;

slim_tick_t lastTick = community->EstimatedLastTick();
// The last tick could be just about anything, so we need some smart axis setup code here – a problem we neglect elsewhere
slim_tick_t lastTick = community->EstimatedLastTick();
// The last tick could be just about anything, so we need some smart axis setup code here – a problem we neglect elsewhere
// since we use hard-coded axis setups in other places. The goal is to (1) have the axis max be >= lastTick, (2) have the axis
// max be == lastTick if lastTick is a reasonably round number (a single-digit multiple of a power of 10, say), (3) have just a few
// other major tick intervals drawn, so labels don't collide or look crowded, and (4) have a few minor tick intervals in between
Expand Down Expand Up @@ -2434,20 +2434,17 @@ size_t QtSLiMGraphView::tallyGUIMutationReferences(slim_objectid_t subpop_id, in

if (subpop) // tally only within our chosen subpop
{
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_)
{
Haplosome &haplosome = *subpop_haplosome[static_cast<size_t>(i)];
if (!haplosome.IsNull())
for (Haplosome *haplosome : ind->haplosomes_)
{
if (!haplosome->IsNull())
{
int mutrun_count = haplosome.mutrun_count_;
int mutrun_count = haplosome->mutrun_count_;

for (int run_index = 0; run_index < mutrun_count; ++run_index)
{
const MutationRun *mutrun = haplosome.mutruns_[run_index];
const MutationRun *mutrun = haplosome->mutruns_[run_index];
const MutationIndex *haplosome_iter = mutrun->begin_pointer_const();
const MutationIndex *haplosome_end_iter = mutrun->end_pointer_const();

Expand All @@ -2463,6 +2460,7 @@ size_t QtSLiMGraphView::tallyGUIMutationReferences(slim_objectid_t subpop_id, in
subpop_total_haplosome_count++;
}
}
}
}

return subpop_total_haplosome_count;
Expand Down
12 changes: 9 additions & 3 deletions QtSLiM/QtSLiMGraphView_1DSampleSFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,18 @@ uint64_t *QtSLiMGraphView_1DSampleSFS::mutation1DSFS(void)
// Get frequencies for a sample taken (with replacement) from subpop1
{
std::vector<Haplosome *> sampleHaplosomes;
std::vector<Haplosome *> &subpopHaplosomes = subpop1->parent_haplosomes_;
size_t subpopHaplosomeCount = subpopHaplosomes.size();
std::vector<Individual *> &subpopIndividuals = subpop1->parent_individuals_;
size_t subpopHaplosomeCount = subpopIndividuals.size() * 2;

if (subpopHaplosomeCount)
for (int i = 0; i < histogramBinCount_ - 1; ++i)
sampleHaplosomes.emplace_back(subpopHaplosomes[random() % subpopHaplosomeCount]);
{
slim_popsize_t haplosome_index = random() % subpopHaplosomeCount;
slim_popsize_t individual_index = haplosome_index >> 1;
Haplosome *haplosome = subpopIndividuals[individual_index]->haplosomes_[haplosome_index & 0x01];

sampleHaplosomes.emplace_back(haplosome);
}

tallyGUIMutationReferences(sampleHaplosomes, selectedMutationTypeIndex_);
}
Expand Down
24 changes: 18 additions & 6 deletions QtSLiM/QtSLiMGraphView_2DSampleSFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,18 @@ uint64_t *QtSLiMGraphView_2DSampleSFS::mutation2DSFS(void)
// Get frequencies for a sample taken from subpop1
{
std::vector<Haplosome *> sample1Haplosomes;
std::vector<Haplosome *> &subpopHaplosomes = subpop1->parent_haplosomes_;
size_t subpopHaplosomeCount = subpopHaplosomes.size();
std::vector<Individual *> &subpopIndividuals = subpop1->parent_individuals_;
size_t subpopHaplosomeCount = subpopIndividuals.size() * 2;

if (subpopHaplosomeCount)
for (int i = 0; i < histogramBinCount_ - 1; ++i)
sample1Haplosomes.emplace_back(subpopHaplosomes[random() % subpopHaplosomeCount]);
{
slim_popsize_t haplosome_index = random() % subpopHaplosomeCount;
slim_popsize_t individual_index = haplosome_index >> 1;
Haplosome *haplosome = subpopIndividuals[individual_index]->haplosomes_[haplosome_index & 0x01];

sample1Haplosomes.emplace_back(haplosome);
}

tallyGUIMutationReferences(sample1Haplosomes, selectedMutationTypeIndex_);
}
Expand All @@ -374,12 +380,18 @@ uint64_t *QtSLiMGraphView_2DSampleSFS::mutation2DSFS(void)
// Get frequencies for a sample taken from subpop2
{
std::vector<Haplosome *> sample2Haplosomes;
std::vector<Haplosome *> &subpopHaplosomes = subpop2->parent_haplosomes_;
size_t subpopHaplosomeCount = subpopHaplosomes.size();
std::vector<Individual *> &subpopIndividuals = subpop2->parent_individuals_;
size_t subpopHaplosomeCount = subpopIndividuals.size() * 2;

if (subpopHaplosomeCount)
for (int i = 0; i < histogramBinCount_ - 1; ++i)
sample2Haplosomes.emplace_back(subpopHaplosomes[random() % subpopHaplosomeCount]);
{
slim_popsize_t haplosome_index = random() % subpopHaplosomeCount;
slim_popsize_t individual_index = haplosome_index >> 1;
Haplosome *haplosome = subpopIndividuals[individual_index]->haplosomes_[haplosome_index & 0x01];

sample2Haplosomes.emplace_back(haplosome);
}

tallyGUIMutationReferences(sample2Haplosomes, selectedMutationTypeIndex_);
}
Expand Down
7 changes: 4 additions & 3 deletions QtSLiM/QtSLiMHaplotypeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ QtSLiMHaplotypeManager::QtSLiMHaplotypeManager(QObject *p_parent, ClusteringMeth

// Fetch haplosomes and figure out what we're going to plot; note that we plot only non-null haplosomes
for (Subpopulation *subpop : selected_subpops)
for (Haplosome *haplosome : subpop->parent_haplosomes_)
if (!haplosome->IsNull())
haplosomes.emplace_back(haplosome);
for (Individual *ind : subpop->parent_individuals_)
for (Haplosome *haplosome : ind->haplosomes_)
if (!haplosome->IsNull())
haplosomes.emplace_back(haplosome);

// If a sample is requested, select that now; sampleSize <= 0 means no sampling
if ((sampleSize > 0) && (haplosomes.size() > sampleSize))
Expand Down
10 changes: 4 additions & 6 deletions SLiMgui/GraphView_MutationFrequencyTrajectory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,15 @@ - (void)fetchDataForFinishedTick

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

if (!haplosome.IsNull())
if (!haplosome->IsNull())
{
int mutrun_count = haplosome.mutrun_count_;
int mutrun_count = haplosome->mutrun_count_;

for (int run_index = 0; run_index < mutrun_count; ++run_index)
{
const MutationRun *mutrun = haplosome.mutruns_[run_index];
const MutationRun *mutrun = haplosome->mutruns_[run_index];
const MutationIndex *haplosome_iter = mutrun->begin_pointer_const();
const MutationIndex *haplosome_end_iter = mutrun->end_pointer_const();

Expand Down
8 changes: 1 addition & 7 deletions SLiMgui/SLiMHaplotypeManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,9 @@ - (instancetype)initWithClusteringMethod:(SLiMHaplotypeClusteringMethod)clusteri
for (Subpopulation *subpop : selected_subpops)
{
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_);

for (Haplosome *haplosome : ind->haplosomes_)
if (!haplosome->IsNull())
haplosomes.emplace_back(haplosome);
}
}
}

// If a sample is requested, select that now; sampleSize <= 0 means no sampling
Expand Down
4 changes: 2 additions & 2 deletions core/chromosome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2831,7 +2831,7 @@ EidosValue_SP Chromosome::ExecuteMethod_drawBreakpoints(EidosGlobalStringID p_me
if (parent && recombination_callbacks.size())
{
// a non-zero number of breakpoints, with recombination callbacks
species_.population_.ApplyRecombinationCallbacks(parent->index_, parent->haplosome1_, parent->haplosome2_, parent_subpop, all_breakpoints, recombination_callbacks);
species_.population_.ApplyRecombinationCallbacks(parent->index_, parent->haplosomes_[0], parent->haplosomes_[1], parent_subpop, all_breakpoints, recombination_callbacks);

if (all_breakpoints.size() > 1)
{
Expand All @@ -2843,7 +2843,7 @@ EidosValue_SP Chromosome::ExecuteMethod_drawBreakpoints(EidosGlobalStringID p_me
else if (parent && recombination_callbacks.size())
{
// zero breakpoints from the SLiM core, but we have recombination() callbacks
species_.population_.ApplyRecombinationCallbacks(parent->index_, parent->haplosome1_, parent->haplosome2_, parent_subpop, all_breakpoints, recombination_callbacks);
species_.population_.ApplyRecombinationCallbacks(parent->index_, parent->haplosomes_[0], parent->haplosomes_[1], parent_subpop, all_breakpoints, recombination_callbacks);

if (all_breakpoints.size() > 1)
{
Expand Down
21 changes: 8 additions & 13 deletions core/haplosome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,8 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_addMutations(EidosGlobalStringID p_

if (focal_modification_child)
{
Haplosome *focal_haplosome_1 = focal_modification_child->haplosome1_, *focal_haplosome_2 = focal_modification_child->haplosome2_;
Haplosome *focal_haplosome_1 = focal_modification_child->haplosomes_[0];
Haplosome *focal_haplosome_2 = focal_modification_child->haplosomes_[1];

for (int haplosome_index = 0; haplosome_index < target_size; ++haplosome_index)
{
Expand Down Expand Up @@ -2486,7 +2487,8 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_addNewMutation(EidosGlobalStringID

if (focal_modification_child)
{
Haplosome *focal_haplosome_1 = focal_modification_child->haplosome1_, *focal_haplosome_2 = focal_modification_child->haplosome2_;
Haplosome *focal_haplosome_1 = focal_modification_child->haplosomes_[0];
Haplosome *focal_haplosome_2 = focal_modification_child->haplosomes_[1];

for (int haplosome_index = 0; haplosome_index < target_size; ++haplosome_index)
{
Expand Down Expand Up @@ -3900,7 +3902,8 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_removeMutations(EidosGlobalStringID

if (focal_modification_child)
{
Haplosome *focal_haplosome_1 = focal_modification_child->haplosome1_, *focal_haplosome_2 = focal_modification_child->haplosome2_;
Haplosome *focal_haplosome_1 = focal_modification_child->haplosomes_[0];
Haplosome *focal_haplosome_2 = focal_modification_child->haplosomes_[1];

for (int haplosome_index = 0; haplosome_index < target_size; ++haplosome_index)
{
Expand Down Expand Up @@ -4142,14 +4145,8 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_removeMutations(EidosGlobalStringID
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_);

for (Haplosome *haplosome : ind->haplosomes_)
haplosome->scratch_ = (haplosome->IsNull() ? 0 : 1);
}
}
}

for (int haplosome_index = 0; haplosome_index < target_size; ++haplosome_index)
Expand Down Expand Up @@ -4177,10 +4174,8 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_removeMutations(EidosGlobalStringID

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

if (haplosome->scratch_ == 1)
{
for (slim_position_t position : unique_positions)
Expand Down
Loading

0 comments on commit 249ab04

Please sign in to comment.