Skip to content

Commit

Permalink
step one, no chromosome for no genetics
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Oct 11, 2024
1 parent b517415 commit 361e2db
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 287 deletions.
14 changes: 11 additions & 3 deletions SLiMgui/ChromosomeView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,18 @@ - (NSRange)selectedRange
{
SLiMWindowController *controller = (SLiMWindowController *)[[self window] windowController];
Species *displaySpecies = [controller focalDisplaySpecies];
Chromosome &chromosome = displaySpecies->TheChromosome();
slim_position_t chromosomeLastPosition = chromosome.last_position_;

return NSMakeRange(0, chromosomeLastPosition + 1); // chromosomeLastPosition + 1 bases are encompassed
if (displaySpecies->chromosomes_.size())
{
Chromosome &chromosome = displaySpecies->TheChromosome();
slim_position_t chromosomeLastPosition = chromosome.last_position_;

return NSMakeRange(0, chromosomeLastPosition + 1); // chromosomeLastPosition + 1 bases are encompassed
}
else
{
return NSMakeRange(0, 0);
}
}
}

Expand Down
1 change: 0 additions & 1 deletion core/haplosome.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class Haplosome : public EidosObject
private:
#endif

// FIXME MULTICHROM chromosome_index_ needs to get set up properly
slim_chromosome_index_t /* uint8_t */ chromosome_index_ = 0; // the index of this haplosome's chromosome
int8_t scratch_; // temporary scratch space that can be used locally in algorithms

Expand Down
63 changes: 21 additions & 42 deletions core/species.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ void Species::AddChromosome(Chromosome *p_chromosome)
case ChromosomeType::kML_HaploidMaleLine:
case ChromosomeType::kHNull_HaploidAutosomeWithNull:
case ChromosomeType::kNullY_YSexChromosomeWithNull:
// FIXME MULTICHROM we need to keep an overall flag at the species level, based on
// the chromosome types in play, and then copy that (and modify it as needed) at
// the subpopulation level so each subpop can potentially differ; or maybe that is
// excessively complex and we should just keep a single species flag; yeah, probably
chromosomes_use_null_haplosomes_ = true;
break;
}
Expand Down Expand Up @@ -1918,50 +1914,25 @@ void Species::RunInitializeCallbacks(void)
// They always use null haplosomes, so any attempt to access their genetics is illegal. They have no mutruns.
// BCH 18 September 2024: They also cannot have any declared chromosomes, or do anything that would cause an
// implicit chromosome to be defined.
// FIXME MULTICHROM eventually no-genetics models should have no chromosome object at all
// BCH 10 October 2024: No-genetics models now have no Chromosome object at all
if (recording_tree_)
EIDOS_TERMINATION << "ERROR (Species::RunInitializeCallbacks): no-genetics species cannot use tree-sequence recording; either add genetic initialization calls, or disable tree-sequence recording." << EidosTerminate();
if (nucleotide_based_)
EIDOS_TERMINATION << "ERROR (Species::RunInitializeCallbacks): no-genetics species cannot be nucleotide-based; either add genetic initialization calls, or turn off nucleotides." << EidosTerminate();

has_genetics_ = false;

// Make a dummy chromosome of length zero, id 0, symbol "0"
Chromosome *dummy_chromosome = new Chromosome(*this, ChromosomeType::kA_DiploidAutosome, 0, "0", /* p_index */ 0, /* p_preferred_mutcount */ 0);
AddChromosome(dummy_chromosome);
has_implicit_chromosome_ = true;
has_currently_initializing_chromosome_ = true;

// initializeMutationRate(): initialize to zero
{
std::vector<slim_position_t> &positions = dummy_chromosome->mutation_end_positions_H_;
std::vector<double> &rates = dummy_chromosome->mutation_rates_H_;
rates.clear();
positions.clear();
rates.emplace_back(0.0);
num_mutrate_inits_++;
}

// initializeRecombinationRate(): initialize to zero
{
std::vector<slim_position_t> &positions = dummy_chromosome->recombination_end_positions_H_;
std::vector<double> &rates = dummy_chromosome->recombination_rates_H_;
rates.clear();
positions.clear();
rates.emplace_back(0.0);
num_recrate_inits_++;
}

community_.chromosome_changed_ = true;
}

if (has_genetics_ && (!has_implicit_chromosome_) && (num_chromosome_inits_ == 0))
EIDOS_TERMINATION << "ERROR (Species::RunInitializeCallbacks): (internal error) a chromosome has not been set up properly." << EidosTerminate();
if (!has_genetics_ && (has_implicit_chromosome_ || (num_chromosome_inits_ > 0)))
EIDOS_TERMINATION << "ERROR (Species::RunInitializeCallbacks): (internal error) a chromosome was set up in a no-genetics model." << EidosTerminate();

// From the initialization that has occurred, there should now be a currently initializing chromosome,
// whether implicitly or explicitly defined. We now close out its definition and check it for
// correctness. If this is a multichromosome model, this has already been done for the previous ones.
EndCurrentChromosome(/* starting_new_chromosome */ false);
if (has_genetics_)
EndCurrentChromosome(/* starting_new_chromosome */ false);

// set a default avatar string if one was not provided; these will be A, B, etc.
if (avatar_.length() == 0)
Expand Down Expand Up @@ -2203,11 +2174,13 @@ void Species::MaintainMutationRegistry(void)

void Species::RecalculateFitness(void)
{
TheChromosome().StartMutationRunExperimentClock();
if (has_genetics_)
TheChromosome().StartMutationRunExperimentClock();

population_.RecalculateFitness(cycle_); // used to be cycle_ + 1 in the WF cycle; removing that 18 Feb 2016 BCH

TheChromosome().StopMutationRunExperimentClock();
if (has_genetics_)
TheChromosome().StopMutationRunExperimentClock();
}

void Species::MaintainTreeSequence(void)
Expand Down Expand Up @@ -2307,12 +2280,14 @@ void Species::WF_GenerateOffspring(void)

if (no_active_callbacks)
{
TheChromosome().StartMutationRunExperimentClock();
if (has_genetics_)
TheChromosome().StartMutationRunExperimentClock();

for (std::pair<const slim_objectid_t,Subpopulation*> &subpop_pair : population_.subpops_)
population_.EvolveSubpopulation(*subpop_pair.second, false, false, false, false, false);

TheChromosome().StopMutationRunExperimentClock();
if (has_genetics_)
TheChromosome().StopMutationRunExperimentClock();
}
else
{
Expand Down Expand Up @@ -2368,12 +2343,14 @@ void Species::WF_GenerateOffspring(void)
}

// then evolve each subpop
TheChromosome().StartMutationRunExperimentClock();
if (has_genetics_)
TheChromosome().StartMutationRunExperimentClock();

for (std::pair<const slim_objectid_t,Subpopulation*> &subpop_pair : population_.subpops_)
population_.EvolveSubpopulation(*subpop_pair.second, mate_choice_callbacks_present, modify_child_callbacks_present, recombination_callbacks_present, mutation_callbacks_present, type_s_dfes_present_);

TheChromosome().StopMutationRunExperimentClock();
if (has_genetics_)
TheChromosome().StopMutationRunExperimentClock();
}
}

Expand All @@ -2387,11 +2364,13 @@ void Species::WF_SwitchToChildGeneration(void)
// population is in a standard state for CheckIndividualIntegrity() at the end of this stage
// BCH 4/22/2023: this is no longer relevant in terms of accurate MutationRun refcounts, since
// we no longer refcount those, but they still need to be zeroed out so they're ready for reuse
TheChromosome().StartMutationRunExperimentClock();
if (has_genetics_)
TheChromosome().StartMutationRunExperimentClock();

population_.ClearParentalHaplosomes();

TheChromosome().StopMutationRunExperimentClock();
if (has_genetics_)
TheChromosome().StopMutationRunExperimentClock();
}

void Species::WF_SwapGenerations(void)
Expand Down
7 changes: 6 additions & 1 deletion core/species.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,12 @@ class Species : public EidosDictionaryUnretained

// Chromosome configuration and access
#warning remove TheChromosome() step by step
inline __attribute__((always_inline)) Chromosome &TheChromosome(void) { return *(chromosomes_[0]); }
inline __attribute__((always_inline)) Chromosome &TheChromosome(void)
{
if (chromosomes_.size() == 0)
EIDOS_TERMINATION << "ERROR (Species::TheChromosome): (internal error) there is no chromosome; check for no genetics first." << EidosTerminate();
return *(chromosomes_[0]);
}
inline __attribute__((always_inline)) const std::vector<Chromosome *> &Chromosomes(void) { return chromosomes_; }
Chromosome *ChromosomeFromID(int64_t p_id);
Chromosome *ChromosomeFromSymbol(const std::string &p_symbol);
Expand Down
Loading

0 comments on commit 361e2db

Please sign in to comment.