libsequence  1.9.5
CoalescentInitialize.cc
1 /*
2 
3  Copyright (C) 2003-2009 Kevin Thornton, krthornt[]@[]uci.edu
4 
5  Remove the brackets to email me.
6 
7  This file is part of libsequence.
8 
9  libsequence is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  libsequence is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  long with libsequence. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #include <Sequence/Coalescent/Initialize.hpp>
25 #include <numeric>
26 #include <cassert>
27 
28 namespace Sequence
29 {
30  namespace coalsim {
31  std::vector<chromosome> init_sample( const std::vector<int> & pop_config,
32  const int & nsites )
43  {
44  assert (! pop_config.empty() );
45  std::vector<chromosome>::size_type nsam =
46  std::vector<chromosome>::size_type(std::accumulate(pop_config.begin(),pop_config.end(),0));
47  std::vector<chromosome> sample(nsam);
48  std::vector<chromosome>::size_type k=0;
49  for(unsigned i = 0 ; i < pop_config.size() ; ++i)
50  {
51  int popsize = pop_config[i];
52  assert(popsize >= 0);
53  for(int j=0;j<popsize;++j)
54  {
55  std::vector<segment> initial_segments(1,segment(0,(nsites>0 ? nsites-1 : 0),int(k)));
56  sample[k++] = chromosome(initial_segments,int(i));
57  }
58  }
59  return sample;
60  }
61 
62  marginal init_marginal( const int & nsam )
68  {
69  std::vector<node> tree(std::vector<node>::size_type(2*nsam-1));
70  for(int i=0;i<nsam;++i)
71  {
72  tree[std::vector<node>::size_type(i)] = node(0.);
73  }
74  return marginal(0,nsam,nsam-1,tree);
75  }
76  }
77 }
A point on a marginal tree at which a coalescent event occurs.
Definition: SimTypes.hpp:151
marginal init_marginal(const int &nsam)
Simple function to initialize a marginal tree.
std::vector< chromosome > init_sample(const std::vector< int > &pop_config, const int &nsites)
A simple function to initialize a sample of chromosomes.
The namespace in which this library resides.
A chromosome is a container of segments.
Definition: SimTypes.hpp:92
A portion of a recombining chromosome.
Definition: SimTypes.hpp:83
The genealogy of a portion of a chromosome on which no recombination has occurred.
Definition: SimTypes.hpp:166