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

Scenario 3 : random mating for 10 generations for one population, then split it into 2 populations and random mating for 10 generations


In [ ]:
%%file main.cpp
//
//  main.cpp
//  OSIM
//
//  Created by Hao Cheng on 3/17/14.
//  Copyright (c) 2014 Hao. All rights reserved.
//

#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 genomeFile="/Users/erxingfangshui/Dropbox/GenSim/GenSim1.3_xcode/genomeInfo.txt";
    string mapFile="/Users/erxingfangshui/Dropbox/GenSim/GenSim1.3_xcode/mapPos.txt";
    string haplotype="/Users/erxingfangshui/Dropbox/GenSim/GenSim1.3_xcode/haplotype.txt";
    
    SimPop osim1(genomeFile,mapFile);
    SimPop osim2(genomeFile,mapFile);
    SimPop osim3(genomeFile,mapFile);


    osim1.popFounders(popSize,haplotype);    
    osim1.popSample(popSize,nGen);

    osim2.sub(osim1,popSize);
    osim3.sub(osim1,popSize);

    osim2.popSample(popSize,nGen);
    osim3.popSample(popSize,nGen);
    
    MatrixXf out;
    out=osim3.getGenotypes();
    ofstream outFile("/Users/erxingfangshui/Desktop/genotype.txt");
    outFile << out;
    cout<<"DONE"<<endl;

    return 0;

}

In [ ]:
%%file main.cpp
//
//  main.cpp
//  OSIM
//
//  Created by Hao Cheng on 3/17/14.
//  Copyright (c) 2014 Hao. All rights reserved.
//

#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 osim1(nChrm,nLoci,chrLength,mutRate);
    SimPop osim2(nChrm,nLoci,chrLength,mutRate);
    SimPop osim3(nChrm,nLoci,chrLength,mutRate);
    osim1.popFounders(popSize);
    
    osim1.popSample(popSize,nGen);

    osim2.sub(osim1,popSize);
    osim3.sub(osim1,popSize);

    osim2.popSample(popSize,nGen);
    osim3.popSample(popSize,nGen);
    
    MatrixXf out;
    out=osim3.getGenotypes();
    ofstream outFile("/Users/erxingfangshui/Desktop/genotype.txt");
    outFile << out;
    cout<<"DONE"<<endl;

    return 0;

}

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

INCPATH = -I/Users/erxingfangshui/Dropbox/CODE/eigen3 -I/Users/erxingfangshui/Dropbox/CODE/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

In [ ]:
%%bash
%%bash
mv makeGenSim ../
mv main.cpp ../
cd ..
make -f makeGenSim

In [ ]:
%%bash
cd ..
./GenSim