1 // $Id: individual.h,v 1.20 2011/03/08 08:16:42 bobgian Exp $
2 
3 /*
4   Copyright 2002  Peter Beerli, Mary Kuhner, Jon Yamato and Joseph Felsenstein
5 
6   This software is distributed free of charge for non-commercial use
7   and is copyrighted.  Of course, we do not guarantee that the software
8   works, and are not responsible for any damage you may cause or have.
9 */
10 
11 // This file defines the class that stores "individual" specific information.
12 
13 #ifndef INDIVIDUAL_H
14 #define INDIVIDUAL_H
15 
16 #include <vector>
17 #include <string>
18 #include <map>
19 //#include <pair>
20 #include "haplotypes.h"
21 #include "vectorx.h"
22 #include "branch.h"                     // for Branch_ptr declaration
23 
24 class Branch;
25 class Random;
26 class DLCell;
27 
28 class Individual
29 {
30   private:
31     long               m_id;
32     LongVec2d          m_phasemarkers; // dim:  loci by markers
33     LongVec2d          m_phasesites;   // dim:  loci by sites (for XML output)
34     string             m_name;
35     vector<Branch_ptr> m_ptips;
36 
37     std::map<std::pair<string, long>, Haplotypes> m_haplotypesmap;
38     std::map<std::pair<string, long>, vector<LocusCell> > m_currentHapsMap;
39     // The string is the name of the locus, and the long is the marker (will
40     //  almost always just be 0, but might not be).
41 
42   public:
Individual()43     Individual()                                  {};
~Individual()44     ~Individual()                                 {};
45     //We accept the default for:
46     //Individual& operator=(const Individual& src);
47     //Individual(const Individual& src);
48 
GetName()49     string          GetName()         const       { return m_name; };
GetAllTips()50     vector<Branch_ptr> GetAllTips()   const       { return m_ptips; };
51     StringVec1d     GetAllTipNames()  const;
GetId()52     long            GetId()           const       { return m_id; };
GetPhaseMarkers()53     const LongVec2d& GetPhaseMarkers() const      { return m_phasemarkers; };
GetPhaseSites()54     const LongVec2d& GetPhaseSites() const        { return m_phasesites; };
55     bool            AnyPhaseUnknownSites() const;
56     bool            MultipleTraitHaplotypes() const;
57 
58     void            PruneSamePhaseUnknownSites();
59     std::pair<long,long> PickRandomPhaseMarker(Random& rs) const;
60     std::pair<string,long> PickRandomHaplotypeMarker() const;
61 
62     void SetPhaseMarkers(const LongVec2d& pm);
63     void SetPhaseSites(const LongVec2d& ps);
SetName(const string & newname)64     void SetName(const string& newname)           { m_name = newname; };
SetTips(vector<Branch_ptr> tps)65     void SetTips(vector<Branch_ptr> tps)          { m_ptips = tps; };
AddTip(Branch_ptr tip)66     void AddTip(Branch_ptr tip)                   { m_ptips.push_back(tip); };
SetId(long newid)67     void SetId(long newid)                        { m_id = newid; };
68     void AddHaplotype(long regnum, string lname, long marker, const StringVec1d& alleles, double penetrance);
69     StringVec1d GetAllelesFor(string lname, long marker) const; //phase 1
70     vector<LocusCell> GetLocusCellsFor(string lname, long marker) const; //phase 2
71     Haplotypes GetHaplotypesFor(string lname, long marker) const;
72     string GetMarkerDataFor(string lname, long marker) const; //phase 3/Output.
73     void ChooseNewHaplotypesFor(string lname, long marker);
74     bool ChooseRandomHaplotypesFor(string lname, long marker);
75     void RandomizeAllHaplotypes();
76 
77     void ChooseFirstHaplotypeFor(string lname, long marker);
78     bool ChooseNextHaplotypeFor(string lname, long marker);
79 
80     // For simulated data.
81     void SetHaplotypes(string lname, long marker, Haplotypes haps);
82     StringVec1d GetAllelesFromDLs(long locus, long marker, bool moving, DataModel_ptr model);
83 
84     bool IsValidIndividual() const;
85     StringVec1d GetTraitXML(long nspaces) const;
86 
87     // Debugging function.
88     void PrintHaplotypesFor(string lname, long marker) const;
89 
90 };
91 
92 typedef vector<Individual> IndVec;
93 
94 #endif // INDIVIDUAL_H
95 
96 //____________________________________________________________________________________
97