Skip to content

Commit

Permalink
fix a bunch of warnings and messages
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoPannetier committed Feb 13, 2024
1 parent d6aba0d commit bf735cc
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Allele.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class Allele {
~Allele() {}
float getAlleleValue() const { return value; };
float getDominanceCoef() const { return dominance; };
float getId() const { return id; }
int getId() const { return id; }
};
#endif
68 changes: 34 additions & 34 deletions GeneticLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,39 @@ GeneticLoad::GeneticLoad(SpeciesTrait* P)
switch (mutationDistribution) {
case UNIFORM:
{
if (!mutationParameters.count(MAX))
cout << endl << ("Error:: adaptive mutation uniform distribution parameter must contain max value (e.g. max= ) \n");
if (mutationParameters.count(MAX) != 1)
cout << endl << ("Error:: adaptive mutation uniform distribution parameter must contain one max value (e.g. max= ) \n");

if (!mutationParameters.count(MIN))
cout << endl << ("Error:: adaptive mutation uniform distribution parameter must contain min value (e.g. min= ) \n");
if (mutationParameters.count(MIN) != 1)
cout << endl << ("Error:: adaptive mutation uniform distribution parameter must contain one min value (e.g. min= ) \n");

break;
}
case NORMAL:
{

if (!mutationParameters.count(MEAN))
cout << endl << ("Error:: adaptive mutation distribution set to normal so parameters must contain mean value (e.g. mean= ) \n");
if (mutationParameters.count(MEAN) != 1)
cout << endl << ("Error:: adaptive mutation distribution set to normal so parameters must contain one mean value (e.g. mean= ) \n");

if (!mutationParameters.count(SDEV))
cout << endl << ("Error:: adaptive mutation distribution set to normal so parameters must contain sdev value (e.g. sdev= ) \n");
if (mutationParameters.count(SDEV) != 1)
cout << endl << ("Error:: adaptive mutation distribution set to normal so parameters must contain one sdev value (e.g. sdev= ) \n");

break;
}
case GAMMA:
{
if (!mutationParameters.count(SHAPE))
cout << endl << ("Error:: adaptive mutation distribution set to gamma so parameters must contain shape value (e.g. shape= ) \n");
if (mutationParameters.count(SHAPE) != 1)
cout << endl << ("Error:: adaptive mutation distribution set to gamma so parameters must contain one shape value (e.g. shape= ) \n");

if (!mutationParameters.count(SCALE))
cout << endl << ("Error:: adaptive mutation distribution set to gamma so parameters must contain scale value (e.g. scale= ) \n");
if (mutationParameters.count(SCALE) != 1)
cout << endl << ("Error:: adaptive mutation distribution set to gamma so parameters must contain one scale value (e.g. scale= ) \n");

break;
}
case NEGEXP:
{
if (!mutationParameters.count(MEAN))
cout << endl << ("Error:: adaptive mutation distribution set to negative exponential (negative decay) so parameters must contain mean value (e.g. mean= ) \n");
if (mutationParameters.count(MEAN) != 1)
cout << endl << ("Error:: adaptive mutation distribution set to negative exponential (negative decay) so parameters must contain one mean value (e.g. mean= ) \n");

break;
}
Expand All @@ -70,38 +70,38 @@ GeneticLoad::GeneticLoad(SpeciesTrait* P)
switch (dominanceDistribution) {
case UNIFORM:
{
if (!dominanceParameters.count(MAX))
cout << endl << ("Error:: adaptive dominance uniform distribution parameter must contain max value (e.g. max= ) \n");
if (dominanceParameters.count(MAX) != 1)
cout << endl << ("Error:: adaptive dominance uniform distribution parameter must contain one max value (e.g. max= ) \n");

if (!dominanceParameters.count(MIN))
cout << endl << ("Error:: adaptive dominance uniform distribution parameter must contain min value (e.g. min= ) \n");
if (dominanceParameters.count(MIN) != 1)
cout << endl << ("Error:: adaptive dominance uniform distribution parameter must contain one min value (e.g. min= ) \n");

break;
}
case NORMAL:
{

if (!dominanceParameters.count(MEAN))
cout << endl << ("Error:: adaptive dominance distribution set to normal so parameters must contain mean value (e.g. mean= ) \n");
if (dominanceParameters.count(MEAN) != 1)
cout << endl << ("Error:: adaptive dominance distribution set to normal so parameters must contain one mean value (e.g. mean= ) \n");

if (!dominanceParameters.count(SDEV))
cout << endl << ("Error:: adaptive dominance distribution set to normal so parameters must contain sdev value (e.g. sdev= ) \n");
if (dominanceParameters.count(SDEV) != 1)
cout << endl << ("Error:: adaptive dominance distribution set to normal so parameters must contain one sdev value (e.g. sdev= ) \n");

break;
}
case GAMMA:
{
if (!dominanceParameters.count(SHAPE))
cout << endl << ("Error:: adaptive dominance distribution set to gamma so parameters must contain shape value (e.g. shape= ) \n");
if (dominanceParameters.count(SHAPE) != 1)
cout << endl << ("Error:: adaptive dominance distribution set to gamma so parameters must contain one shape value (e.g. shape= ) \n");

if (!dominanceParameters.count(SCALE))
cout << endl << ("Error:: adaptive dominance distribution set to gamma so parameters must contain scale value (e.g. scale= ) \n");
if (dominanceParameters.count(SCALE) != 1)
cout << endl << ("Error:: adaptive dominance distribution set to gamma so parameters must contain one scale value (e.g. scale= ) \n");

break;
}
case NEGEXP:
{
if (!dominanceParameters.count(MEAN))
if (dominanceParameters.count(MEAN) != 1)
cout << endl << ("Error:: adaptive dominance distribution set to negative exponential (negative decay) so parameters must contain mean value (e.g. mean= ) \n");

break;
Expand Down Expand Up @@ -363,8 +363,8 @@ float GeneticLoad::express() {

for (auto const& [locus, pAllelePair] : genes)
{
auto pAlleleLeft = (!pAllelePair[0]) ? wildType : pAllelePair[0];
auto pAlleleRight = (!pAllelePair[1]) ? wildType : pAllelePair[1];
shared_ptr<Allele> pAlleleLeft = (!pAllelePair[0]) ? wildType : pAllelePair[0];
shared_ptr<Allele> pAlleleRight = (!pAllelePair[1]) ? wildType : pAllelePair[1];

if (pAlleleLeft.get()->getId() != pAlleleRight.get()->getId()) // heterozygote
{
Expand All @@ -391,9 +391,9 @@ bool GeneticLoad::isHeterozygoteAtLocus(int locus) const {
if (it == genes.end()) //not found so must be wildtype homozygous
return false;
else {
auto a = (!it->second[0]) ? wildType : it->second[0];
auto b = (!it->second[1]) ? wildType : it->second[1];
return a != b;
shared_ptr<Allele> alleleRight = (!it->second[0]) ? wildType : it->second[0];
shared_ptr<Allele> alleleLeft = (!it->second[1]) ? wildType : it->second[1];
return alleleRight != alleleLeft;
}
}

Expand All @@ -407,8 +407,8 @@ int GeneticLoad::countHeterozygoteLoci() const {
int count = 0;

for (auto const& [locus, allelePair] : genes) {
auto alleleLeft = (!allelePair[0]) ? wildType : allelePair[0];
auto alleleRight = (!allelePair[1]) ? wildType : allelePair[1];
shared_ptr<Allele> alleleLeft = (!allelePair[0]) ? wildType : allelePair[0];
shared_ptr<Allele> alleleRight = (!allelePair[1]) ? wildType : allelePair[1];
count += alleleLeft != alleleRight;
}
return count;
Expand Down
6 changes: 3 additions & 3 deletions Individual.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct crwData : trfrData { // to hold data for CRW movement model
void clone(const trfrData& copyFrom) {


auto pCopy = dynamic_cast<const crwData&>(copyFrom);
const crwData& pCopy = dynamic_cast<const crwData&>(copyFrom);

stepLength = pCopy.stepLength;
rho = pCopy.rho;
Expand Down Expand Up @@ -154,7 +154,7 @@ struct smsData : trfrData {
//static float stepMort;
//static bool straigtenPath;

smsData(locn prevA, locn goalA) : prev(prevA), goal(goalA), dp(0.0), gb(0.0), alphaDB(0.0), betaDB(0.0) {}
smsData(locn prevA, locn goalA) : prev(prevA), goal(goalA), dp(0.0), gb(0.0), alphaDB(0.0), betaDB(0) {}
~smsData() {}


Expand Down Expand Up @@ -206,7 +206,7 @@ struct kernelData : trfrData {
movement_t getType() { return KERNEL; }

void clone(const trfrData& copyFrom) {
auto pCopy = dynamic_cast<const kernelData&>(copyFrom);
const kernelData& pCopy = dynamic_cast<const kernelData&>(copyFrom);
meanDist1 = pCopy.meanDist1;
meanDist2 = pCopy.meanDist2;
probKern1 = pCopy.probKern1;
Expand Down
14 changes: 7 additions & 7 deletions NeutralStatsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// ----------------------------------------------------------------------------------------

NeutralStatsManager::NeutralStatsManager(set<int> const& patchList, const int nLoci) {
this->_fst_matrix = PatchMatrix(patchList.size(), patchList.size());
this->_fst_matrix = PatchMatrix(static_cast<int>(patchList.size()), static_cast<int>(patchList.size()));
globalAlleleTable.reserve(nLoci); //don't have to be pointers, not shared or moved
}

Expand Down Expand Up @@ -282,17 +282,17 @@ void NeutralStatsManager::calculateFstatWC(set<int> const& patchList, const int
int patchSize = pPop->sampleSize();
if (patchSize) {
extantPs++;
sum_weights += (patchSize * patchSize / nInds);
sum_weights += (patchSize * patchSize / static_cast<double>(nInds));
}
}

_n_extantPopulations = extantPs;
_n_individuals = nInds;

n_bar = nInds / extantPs;
n_bar = nInds / static_cast<double>(extantPs);
n_c = (nInds - sum_weights) / (extantPs - 1);
inverse_n_bar = 1 / (n_bar - 1);
inverse_n_total = 1 / nInds;
inverse_n_bar = 1.0 / (n_bar - 1);
inverse_n_total = 1.0 / nInds;

double var;
double s2, p_bar, h_bar;
Expand Down Expand Up @@ -359,7 +359,7 @@ void NeutralStatsManager::calculateFstatWC_MS(set<int> const& patchList, const i
int patchSize = pPop->sampleSize();
if (patchSize) {
extantPs++;
sum_weights += (patchSize * patchSize / nInds);
sum_weights += (patchSize * patchSize / static_cast<double>(nInds));
}

}
Expand Down Expand Up @@ -550,7 +550,7 @@ void NeutralStatsManager::setFstMatrix(set<int> const& patchList, const int nInd

copy(patchList.begin(), patchList.end(), std::back_inserter(patchVect)); //needs to be in vector to iterate over, copy preserves order

int nPatches = patchList.size();
int nPatches = static_cast<int>(patchList.size());

//initialise

Expand Down
6 changes: 3 additions & 3 deletions Population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void Population::updateAlleleTable() {
std::for_each(alleleTable.begin(),
alleleTable.end(),
[&](NeutralData& v) -> void {
v.setFrequencies(sampledInds.size() * 2);
v.setFrequencies(static_cast<int>(sampledInds.size()) * 2);
//v->divideHeteros(sampledInds.size()); //weir and cockerham doesn't need this division??
});
}
Expand Down Expand Up @@ -926,7 +926,7 @@ void Population::fledge(void)
}

Individual* Population::sampleInd() const {
int index = pRandom->IRandom(0, inds.size() - 1);
int index = pRandom->IRandom(0, static_cast<int>(inds.size() - 1));
return inds[index];
}

Expand All @@ -953,7 +953,7 @@ void Population::sampleIndsWithoutReplacement(string n, const set<int>& sampleSt
}

int Population::sampleSize() const {
return sampledInds.size();
return static_cast<int>(sampledInds.size());
}

set<Individual*> Population::getIndividualsInStage(int stage) {
Expand Down
36 changes: 18 additions & 18 deletions QTLTrait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ QTLTrait::QTLTrait(SpeciesTrait* P)
switch (mutationDistribution) {
case UNIFORM:
{
if (!mutationParameters.count(MAX))
if (mutationParameters.count(MAX) != 1)
cout << endl << ("Error:: mutation uniform qtl distribution parameter must contain max value (e.g. max= ) \n");

if (!mutationParameters.count(MIN))
if (mutationParameters.count(MIN) != 1)
cout << endl << ("Error:: mutation uniform qtl distribution parameter must contain min value (e.g. min= ) \n");

_mutate_func_ptr = &QTLTrait::mutateUniform;
break;
}
case NORMAL:
{
if (!mutationParameters.count(MEAN))
if (mutationParameters.count(MEAN) != 1)
cout << endl << ("Error:: qtl mutation distribution set to normal so parameters must contain mean value (e.g. mean= ) \n");

if (!mutationParameters.count(SDEV))
if (mutationParameters.count(SDEV) != 1)
cout << endl << ("Error::qtl mutation distribution set to normal so parameters must contain sdev value (e.g. sdev= ) \n");

_mutate_func_ptr = &QTLTrait::mutateNormal;
Expand All @@ -55,10 +55,10 @@ QTLTrait::QTLTrait(SpeciesTrait* P)
switch (initialDistribution) {
case UNIFORM:
{
if (!initialParameters.count(MAX))
if (initialParameters.count(MAX) != 1)
cout << endl << ("Error:: initial uniform qtl distribution parameter must contain max value (e.g. max= ) \n");

if (!initialParameters.count(MIN))
if (initialParameters.count(MIN) != 1)
cout << endl << ("Error:: initial uniform qtl distribution parameter must contain min value (e.g. min= ) \n");

float maxD = initialParameters.find(MAX)->second;
Expand All @@ -69,10 +69,10 @@ QTLTrait::QTLTrait(SpeciesTrait* P)
}
case NORMAL:
{
if (!initialParameters.count(MEAN))
if (initialParameters.count(MEAN) != 1)
cout << endl << ("Error:: initial normal qtl distribution parameter must contain mean value (e.g. mean= ) \n");

if (!initialParameters.count(SDEV))
if (initialParameters.count(SDEV) != 1)
cout << endl << ("Error:: initial normal qtl distribution parameter must contain sdev value (e.g. sdev= ) \n");

float mean = initialParameters.find(MEAN)->second;
Expand Down Expand Up @@ -209,18 +209,18 @@ void QTLTrait::inheritDiploid(sex_t whichChromosome, map<int, vector<shared_ptr<

auto it = recomPositions.lower_bound(parentGenes.begin()->first);

unsigned int nextBreakpoint = *it;
int nextBreakpoint = *it;

auto distance = std::distance(recomPositions.begin(), it);
if (distance % 2 != 0)
parentChromosome = !parentChromosome; //switch chromosome
parentChromosome = 1 - parentChromosome; //switch chromosome

for (auto const& [locus, allelePair] : parentGenes) {

while (locus > nextBreakpoint) {
std::advance(it, 1);
nextBreakpoint = *it;
parentChromosome = !parentChromosome; //switch chromosome
parentChromosome = 1 - parentChromosome; //switch chromosome
}

if (locus <= nextBreakpoint) {
Expand Down Expand Up @@ -258,10 +258,10 @@ void QTLTrait::inheritInitialParameters(sex_t whichChromosome, map<int, vector<s
switch (initialDistribution) {
case UNIFORM:
{
if (!initialParameters.count(MAX))
if (initialParameters.count(MAX) != 1)
cout << endl << ("Error:: initial uniform qtl distribution parameter must contain max value (e.g. max= ) \n");

if (!initialParameters.count(MIN))
if (initialParameters.count(MIN) != 1)
cout << endl << ("Error:: initial uniform qtl distribution parameter must contain min value (e.g. min= ) \n");

float maxD = initialParameters.find(MAX)->second;
Expand All @@ -273,10 +273,10 @@ void QTLTrait::inheritInitialParameters(sex_t whichChromosome, map<int, vector<s
}
case NORMAL:
{
if (!initialParameters.count(MEAN))
if (initialParameters.count(MEAN) != 1)
cout << endl << ("Error:: initial normal qtl distribution parameter must contain mean value (e.g. mean= ) \n");

if (!initialParameters.count(SDEV))
if (initialParameters.count(SDEV) != 1)
cout << endl << ("Error:: initial normal qtl distribution parameter must contain sdev value (e.g. sdev= ) \n");

float mean = initialParameters.find(MEAN)->second;
Expand All @@ -303,7 +303,7 @@ void QTLTrait::inheritInitialParameters(sex_t whichChromosome, map<int, vector<s

void QTLTrait::initialiseNormal(float mean, float sd) {

const auto positions = pSpeciesTrait->getPositions();
const set<int> positions = pSpeciesTrait->getPositions();
short ploidy = pSpeciesTrait->getPloidy();

for (auto position : positions) {
Expand All @@ -318,7 +318,7 @@ void QTLTrait::initialiseNormal(float mean, float sd) {

void QTLTrait::initialiseUniform(float min, float max) {

const auto positions = pSpeciesTrait->getPositions();
const set<int> positions = pSpeciesTrait->getPositions();
short ploidy = pSpeciesTrait->getPloidy();

for (auto position : positions) {
Expand All @@ -341,7 +341,7 @@ float QTLTrait::expressAdditive() {

for (auto const& [locus, allelePair] : genes)
{
for (auto m : allelePair)
for (const std::shared_ptr<Allele> m : allelePair)
phenotype += m->getAlleleValue();
}
return phenotype;
Expand Down
Loading

0 comments on commit bf735cc

Please sign in to comment.