Commit f335f551 authored by E.L.Cortegano's avatar E.L.Cortegano

Skip computation of coancestry matrix for file format conversion

parent 6122163a
Pipeline #149789233 passed with stages
in 3 minutes and 36 seconds
......@@ -44,10 +44,10 @@ void convert2gnp (std::string filename, std::vector<population>& deme, const all
while (max /= 10) ++digits;
if (DEBUG) std::cout << std::endl;
for (std::size_t p (0); p < deme.size(); p++){
for (std::size_t p (0); p < deme.size(); ++p) {
if (DEBUG) std::cout << "\r Writting population " << p+1 << " / " << deme.size();
genepop_file << "Pop" << std::endl;
for (std::size_t i(0); i<deme[p].getPopulationSize(); i++){
for (std::size_t i(0); i<deme[p].getPopulationSize(); ++i) {
genepop_file << deme[p].getLabel() << p << i << ", ";
for (std::size_t l(0); l< loci; l++){
allele_t a (deme[p].getIndividual(i).getLocus(l).getA(0));
......
......@@ -50,15 +50,17 @@ Metapop::Metapop (std::string file_name, const MTPConfigFile& config) {
if (config.get_datafile_sformat()=="pedigree") read_pedigree = true;
// Read and format input file
bool compute_coancestry (true);
if (config.get_convert_mode() != "none") compute_coancestry = false;
use_nucleotides = config.get_use_nucleotides();
std::string data ((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
clean_datafile(data);
filename = file_name;
if (input_format == GNP) input_genepop (data);
else if (input_format == PED) input_pedfile (data, read_pedigree, config.get_rm_file());
else this->update (data); // input_metapop
if (input_format == GNP) input_genepop (data, compute_coancestry);
else if (input_format == PED) input_pedfile (data, read_pedigree, config.get_rm_file(), compute_coancestry);
else this->update (data, compute_coancestry); // input_metapop
if (for_simulation) use_nucleotides = false;
// Read management file
......@@ -117,8 +119,8 @@ Metapop::Metapop ( std::string file_name, const MTPConfigFile& config, std::stri
filename = file_name;
input_format = config.get_datafile_format();
if (mode == "gp2mtp") input_genepop (data);
else if (mode == "ped2mtp") input_pedfile (data, false,"");
if (mode == "gp2mtp") input_genepop (data, false);
else if (mode == "ped2mtp") input_pedfile (data, false,"", false);
else {
std::cerr << "Unknown conversion mode. Select one of 'none', 'mtp2gp' or 'mtp2ped'." << std::endl;
exit(-1);
......@@ -178,7 +180,7 @@ Metapop::Metapop ( const Metapop& original) { // Copy constructor for bootstrap
* --------------------------------------------------------------------------------------------
* Read a string with the content of the datafile, and update its attributes.
* ********************************************************************************************/
void Metapop::update (std::string file) {
void Metapop::update (std::string file, bool compute_coancestry) {
// Initialize variables
n_subpops = 0;
......@@ -199,6 +201,7 @@ void Metapop::update (std::string file) {
// Read metapop file
this->input_metapop(file);
if (!compute_coancestry) return;
// Calculate coancestry matrix from molecular markers (if it hasn't been inputed)
// should this be part of metapop class?
......@@ -1054,7 +1057,7 @@ void Metapop::input_metapop (std::string file) {
* --------------------------------------------------------------------------------------------
* This function creates an intern and simplified metapop input file from a genepop input file
* ********************************************************************************************/
void Metapop::input_genepop (std::string str) {
void Metapop::input_genepop (std::string str, bool compute_coancestry) {
use_molecular_markers = true;
......@@ -1162,6 +1165,7 @@ void Metapop::input_genepop (std::string str) {
}
// Calculate coancestry
if (!compute_coancestry) return;
this->coancestry_matrix();
}
......@@ -1171,7 +1175,7 @@ void Metapop::input_genepop (std::string str) {
* --------------------------------------------------------------------------------------------
* This function creates an intern and simplified metapop input file from a plink PED file
* ********************************************************************************************/
void Metapop::input_pedfile (std::string str, bool calc_pedigree, std::string rmatrix_filename) {
void Metapop::input_pedfile (std::string str, bool calc_pedigree, std::string rmatrix_filename, bool compute_coancestry) {
if (!calc_pedigree) use_molecular_markers = true;
else {
......@@ -1300,6 +1304,7 @@ void Metapop::input_pedfile (std::string str, bool calc_pedigree, std::string rm
}
// Test pedigree
if (!compute_coancestry) return;
if (calc_pedigree) test_pedigree(pedigree);
// Calculate coancestry
......
......@@ -148,7 +148,7 @@ public:
Metapop ( std::string , const MTPConfigFile& );
Metapop ( std::string , const MTPConfigFile& , std::string ); // user for conversion to metapop format
Metapop ( const Metapop& ); // copy constructor for bootstrap
void update ( std::string );
void update ( std::string , bool );
void check ( const MTPConfigFile& );
~Metapop ();
......@@ -209,8 +209,8 @@ protected:
// Input methods
void input_metapop ( std::string );
void input_genepop ( std::string );
void input_pedfile ( std::string, bool, std::string);
void input_genepop ( std::string , bool );
void input_pedfile ( std::string, bool, std::string , bool );
void default_mng ();
void input_management ( std::string );
void end_body ( std::size_t& , std::size_t& , std::size_t& , std::string& , std::vector<individual>& );
......
......@@ -778,7 +778,7 @@ void printSolution ( const MTPConfigFile& config, Metapop& metapop, const Calcul
}
//Establish the input for the new generation
if (simMode) metapop.update (dat.str());
if (simMode) metapop.update (dat.str(), true);
fr.close();
/* SAVE SIMULATION RESULTS */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment