This file shows several main file demos for different mating structures.

Scenario 1 : random mating for 10 generations for one population

reading real genotypes from files


In [5]:
%%file main.cpp

#include <iostream>
#include <fstream>
#include "cohort.h"
#include "tools.h"
#include "simPop.h"
#include "global.h"
#include "parmMap.h"

int main(int argc, const char * argv[])
{   
    ///user-defined parameters and map positions
    unsigned popSize =  10;
    unsigned nGen    =  10;
  
    string path="/Users/erxingfangshui/Dropbox/GenSim/GenSim1.4/data/";
    string genomeFile=path+"genomeInfo.txt";
    string mapFile=path+"mapPos.txt";
    string haplotype=path+"haplotype.txt";
    
    SimPop osim(genomeFile,mapFile);
    osim.popFounders(popSize,haplotype);
    
    osim.popSample(popSize,nGen);
    MatrixXf out;
    out=osim.getGenotypes();
    ofstream outFile(path+"genotype.txt");
    outFile << out;
    
    return 0;

}


Overwriting main.cpp

randomly generate genotypes


In [ ]:
%%file main.cpp

#include <iostream>
#include <fstream>
#include "cohort.h"
#include "tools.h"
#include "simPop.h"
#include "global.h"
#include "parmMap.h"

int main(int argc, const char * argv[])
{   

    ///constant nLoci, chrLength and random map positions
    unsigned nLoci   =  100;
    unsigned nChrm   =  1;
    double chrLength =  0.01;
    unsigned popSize =  100;
    unsigned nGen    =  10;
    double   mutRate =  1e-5;
    
    SimPop osim(nChrm,nLoci,chrLength,mutRate);
    osim.popFounders(popSize);
    osim.popSample(popSize,nGen);
    MatrixXf out;
    out=osim.getGenotypes();
    ofstream outFile("genotype.example");
    outFile << out;
    cout<<"DONE"<<endl;
    
    return 0;

}

In [2]:
%%file  makeGenSim
#############################################################################
# Makefile for building: OSim

myPath = /Users/erxingfangshui/Dropbox/CODE
INCPATH = -I $(myPath)/eigen3 -I $(myPath)/boost

GenSim:	main.o libGenSim.a
	g++ -o GenSim main.o libGenSim.a 

main.o: main.cpp 
	g++ $(INCPATH) -c -o main.o main.cpp

clean:
	\rm main.o GenSim


Writing makeGenSim

In [2]:
%%bash
path=/Users/erxingfangshui/Dropbox/GenSim/GenSim1.4
mv makeGenSim $path
mv main.cpp $path

cd $path
make -f makeGenSim


g++ -I /Users/erxingfangshui/Dropbox/CODE/eigen3 -I /Users/erxingfangshui/Dropbox/CODE/boost -c -o main.o main.cpp
g++ -o GenSim main.o libGenSim.a 
mv: makeGenSim: No such file or directory
In file included from main.cpp:4:
In file included from ./cohort.h:14:
In file included from ./animal_class.h:22:
./genome_info.h:55:14: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
        for( auto &i : *this){
             ^
./genome_info.h:55:22: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
        for( auto &i : *this){
                     ^
2 warnings generated.

In [3]:
%%bash
path=/Users/erxingfangshui/Dropbox/GenSim/GenSim1.4
cd $path
./GenSim


Sampling 10 animals from known genotypes into base population.
Generation 1 ---> Sampling 10 children into next generation.
Generation 2 ---> Sampling 10 children into next generation.
Generation 3 ---> Sampling 10 children into next generation.
Generation 4 ---> Sampling 10 children into next generation.
Generation 5 ---> Sampling 10 children into next generation.
Generation 6 ---> Sampling 10 children into next generation.
Generation 7 ---> Sampling 10 children into next generation.
Generation 8 ---> Sampling 10 children into next generation.
Generation 9 ---> Sampling 10 children into next generation.