diff --git a/Allele.h b/Allele.h index 7f8a0a8..1b00706 100644 --- a/Allele.h +++ b/Allele.h @@ -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 \ No newline at end of file diff --git a/GeneticLoad.cpp b/GeneticLoad.cpp index 4fd5588..b467c9a 100644 --- a/GeneticLoad.cpp +++ b/GeneticLoad.cpp @@ -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; } @@ -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; @@ -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 pAlleleLeft = (!pAllelePair[0]) ? wildType : pAllelePair[0]; + shared_ptr pAlleleRight = (!pAllelePair[1]) ? wildType : pAllelePair[1]; if (pAlleleLeft.get()->getId() != pAlleleRight.get()->getId()) // heterozygote { @@ -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 alleleRight = (!it->second[0]) ? wildType : it->second[0]; + shared_ptr alleleLeft = (!it->second[1]) ? wildType : it->second[1]; + return alleleRight != alleleLeft; } } @@ -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 alleleLeft = (!allelePair[0]) ? wildType : allelePair[0]; + shared_ptr alleleRight = (!allelePair[1]) ? wildType : allelePair[1]; count += alleleLeft != alleleRight; } return count; diff --git a/Individual.h b/Individual.h index 2245c1a..71d986a 100644 --- a/Individual.h +++ b/Individual.h @@ -123,7 +123,7 @@ struct crwData : trfrData { // to hold data for CRW movement model void clone(const trfrData& copyFrom) { - auto pCopy = dynamic_cast(copyFrom); + const crwData& pCopy = dynamic_cast(copyFrom); stepLength = pCopy.stepLength; rho = pCopy.rho; @@ -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() {} @@ -206,7 +206,7 @@ struct kernelData : trfrData { movement_t getType() { return KERNEL; } void clone(const trfrData& copyFrom) { - auto pCopy = dynamic_cast(copyFrom); + const kernelData& pCopy = dynamic_cast(copyFrom); meanDist1 = pCopy.meanDist1; meanDist2 = pCopy.meanDist2; probKern1 = pCopy.probKern1; diff --git a/NeutralStatsManager.cpp b/NeutralStatsManager.cpp index de578c5..3c0b15a 100644 --- a/NeutralStatsManager.cpp +++ b/NeutralStatsManager.cpp @@ -29,7 +29,7 @@ // ---------------------------------------------------------------------------------------- NeutralStatsManager::NeutralStatsManager(set const& patchList, const int nLoci) { - this->_fst_matrix = PatchMatrix(patchList.size(), patchList.size()); + this->_fst_matrix = PatchMatrix(static_cast(patchList.size()), static_cast(patchList.size())); globalAlleleTable.reserve(nLoci); //don't have to be pointers, not shared or moved } @@ -282,17 +282,17 @@ void NeutralStatsManager::calculateFstatWC(set const& patchList, const int int patchSize = pPop->sampleSize(); if (patchSize) { extantPs++; - sum_weights += (patchSize * patchSize / nInds); + sum_weights += (patchSize * patchSize / static_cast(nInds)); } } _n_extantPopulations = extantPs; _n_individuals = nInds; - n_bar = nInds / extantPs; + n_bar = nInds / static_cast(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; @@ -359,7 +359,7 @@ void NeutralStatsManager::calculateFstatWC_MS(set const& patchList, const i int patchSize = pPop->sampleSize(); if (patchSize) { extantPs++; - sum_weights += (patchSize * patchSize / nInds); + sum_weights += (patchSize * patchSize / static_cast(nInds)); } } @@ -550,7 +550,7 @@ void NeutralStatsManager::setFstMatrix(set 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(patchList.size()); //initialise diff --git a/Population.cpp b/Population.cpp index 199e3c6..4615951 100644 --- a/Population.cpp +++ b/Population.cpp @@ -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(sampledInds.size()) * 2); //v->divideHeteros(sampledInds.size()); //weir and cockerham doesn't need this division?? }); } @@ -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(inds.size() - 1)); return inds[index]; } @@ -953,7 +953,7 @@ void Population::sampleIndsWithoutReplacement(string n, const set& sampleSt } int Population::sampleSize() const { - return sampledInds.size(); + return static_cast(sampledInds.size()); } set Population::getIndividualsInStage(int stage) { diff --git a/QTLTrait.cpp b/QTLTrait.cpp index 6c9d451..1b38fee 100644 --- a/QTLTrait.cpp +++ b/QTLTrait.cpp @@ -20,10 +20,10 @@ 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; @@ -31,10 +31,10 @@ QTLTrait::QTLTrait(SpeciesTrait* P) } 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; @@ -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; @@ -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; @@ -209,18 +209,18 @@ void QTLTrait::inheritDiploid(sex_t whichChromosome, mapfirst); - 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) { @@ -258,10 +258,10 @@ void QTLTrait::inheritInitialParameters(sex_t whichChromosome, mapsecond; @@ -273,10 +273,10 @@ void QTLTrait::inheritInitialParameters(sex_t whichChromosome, mapsecond; @@ -303,7 +303,7 @@ void QTLTrait::inheritInitialParameters(sex_t whichChromosome, mapgetPositions(); + const set positions = pSpeciesTrait->getPositions(); short ploidy = pSpeciesTrait->getPloidy(); for (auto position : positions) { @@ -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 positions = pSpeciesTrait->getPositions(); short ploidy = pSpeciesTrait->getPloidy(); for (auto position : positions) { @@ -341,7 +341,7 @@ float QTLTrait::expressAdditive() { for (auto const& [locus, allelePair] : genes) { - for (auto m : allelePair) + for (const std::shared_ptr m : allelePair) phenotype += m->getAlleleValue(); } return phenotype; diff --git a/SNPTrait.cpp b/SNPTrait.cpp index 167cb84..102d9cf 100644 --- a/SNPTrait.cpp +++ b/SNPTrait.cpp @@ -21,7 +21,7 @@ SNPTrait::SNPTrait(SpeciesTrait* P) if (mutationDistribution != SSM && mutationDistribution != KAM) cout << endl << ("Error:: wrong mutation distribution for neutral markers, must be KAM or SSM \n"); - if (!mutationParameters.count(MAX)) + if (mutationParameters.count(MAX) != 1) cout << endl << ("Error:: KAM or SSM mutation distribution parameter must contain max value (e.g. max= ), max cannot exceed 256 \n"); if (wildType == -999) @@ -39,8 +39,8 @@ SNPTrait::SNPTrait(SpeciesTrait* P) switch (initialDistribution) { case UNIFORM: { - if (!initialParameters.count(MAX)) - cout << endl << "Error:: initial SNP/Microsat distribution parameter must contain max value if set to UNIFORM (e.g. max= ), max cannot exceed " << maxSNPAlleles << "\n"; + if (initialParameters.count(MAX) != 1) + cout << endl << "Error:: initial SNP/Microsat distribution parameter must contain one max value if set to UNIFORM (e.g. max= ), max cannot exceed " << maxSNPAlleles << "\n"; float maxD = initialParameters.find(MAX)->second; if (maxD > maxSNPAlleles) { @@ -83,7 +83,6 @@ SNPTrait::SNPTrait(const SNPTrait& T) : // ---------------------------------------------------------------------------------------- void SNPTrait::mutate_KAM() { - const int positionsSize = pProtoTrait->getPositionsSize(); const auto& positions = pProtoTrait->getPositions(); const short ploidy = pProtoTrait->getPloidy(); diff --git a/Species.cpp b/Species.cpp index ca68b90..459c3d3 100644 --- a/Species.cpp +++ b/Species.cpp @@ -478,7 +478,7 @@ set Species::getTraitTypes() { } int Species::getNTraits() const { - return spTraitTable.size(); + return static_cast(spTraitTable.size()); } int Species::getNPositionsForTrait(const TraitType trait) const { diff --git a/SpeciesTrait.cpp b/SpeciesTrait.cpp index aa56340..f8c5d8a 100644 --- a/SpeciesTrait.cpp +++ b/SpeciesTrait.cpp @@ -34,7 +34,7 @@ SpeciesTrait::SpeciesTrait(vector parameters, Species* pSpecies) { if (pSpecies->getNumberOfNeutralLoci() > 0) cout << endl << "Traits file: WARNING - can only have one set of neutral markers, overwriting previous" << endl; - else pSpecies->setNumberOfNeutralLoci(positions.size()); + else pSpecies->setNumberOfNeutralLoci(static_cast(positions.size())); } } diff --git a/SpeciesTrait.h b/SpeciesTrait.h index c31b21e..9a634cb 100644 --- a/SpeciesTrait.h +++ b/SpeciesTrait.h @@ -36,7 +36,7 @@ class SpeciesTrait { float getMutationRate() const { return mutationRate; } short getPloidy() const { return ploidy; } set& getPositions() { return positions; } // returning by reference, make sure receiver is const - int getPositionsSize() const { return positions.size(); } + int getPositionsSize() const { return static_cast(positions.size()); } bool isInherited() const { return inherited; } DistributionType getMutationDistribution() const { return mutationDistribution; }; map getMutationParameters() const { return mutationParameters; }; diff --git a/SubCommunity.cpp b/SubCommunity.cpp index 67dbebf..5164444 100644 --- a/SubCommunity.cpp +++ b/SubCommunity.cpp @@ -1111,9 +1111,6 @@ traitsums SubCommunity::outTraits(traitCanvas tcanv, } // CURRENTLY INDIVIDUAL VARIATION CANNOT BE SEX-DEPENDENT -// ngenes = 1; - double mnS0[2], mnAlpha[2], mnBeta[2], sdS0[2], sdAlpha[2], sdBeta[2]; - if (writefile) outtraits << endl; for (int s = 0; s < NSEXES; s++) {