~ubuntu-branches/ubuntu/trusty/libbpp-popgen/trusty

« back to all changes in this revision

Viewing changes to src/Bpp/PopGen/BiAlleleMonolocusGenotype.cpp

  • Committer: Package Import Robot
  • Author(s): Julien Dutheil
  • Date: 2013-03-07 10:51:00 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130307105100-7ij3w7iyab9t2mbt
Tags: 2.1.0-1
Bug fixed and warnings removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
   for population genetics analysis.
12
12
 
13
13
   This software is governed by the CeCILL  license under French law and
14
 
   abiding by the rules of distribution of free software.  You can  use, 
 
14
   abiding by the rules of distribution of free software.  You can  use,
15
15
   modify and/ or redistribute the software under the terms of the CeCILL
16
16
   license as circulated by CEA, CNRS and INRIA at the following URL
17
 
   "http://www.cecill.info". 
 
17
   "http://www.cecill.info".
18
18
 
19
19
   As a counterpart to the access to the source code and  rights to copy,
20
20
   modify and redistribute granted by the license, users are provided only
21
21
   with a limited warranty  and the software's author,  the holder of the
22
22
   economic rights,  and the successive licensors  have only  limited
23
 
   liability. 
 
23
   liability.
24
24
 
25
25
   In this respect, the user's attention is drawn to the risks associated
26
26
   with loading,  using,  modifying and/or developing or reproducing the
29
29
   therefore means  that it is reserved for developers  and  experienced
30
30
   professionals having in-depth computer knowledge. Users are therefore
31
31
   encouraged to load and test the software's suitability as regards their
32
 
   requirements in conditions enabling the security of their systems and/or 
33
 
   data to be ensured and,  more generally, to use and operate it in the 
34
 
   same conditions as regards security. 
 
32
   requirements in conditions enabling the security of their systems and/or
 
33
   data to be ensured and,  more generally, to use and operate it in the
 
34
   same conditions as regards security.
35
35
 
36
36
   The fact that you are presently reading this means that you have had
37
37
   knowledge of the CeCILL license and that you accept its terms.
38
 
   */
 
38
 */
39
39
 
40
40
#include "BiAlleleMonolocusGenotype.h"
41
41
 
42
42
using namespace bpp;
43
43
using namespace std;
44
44
 
45
 
//** Class constructor: *******************************************************/
 
45
// ** Class constructor: *******************************************************/
46
46
 
47
47
BiAlleleMonolocusGenotype::BiAlleleMonolocusGenotype(
48
 
    unsigned int first_allele_index,
49
 
    unsigned int second_allele_index): allele_index_(vector<unsigned int>(2))
 
48
  size_t first_allele_index,
 
49
  size_t second_allele_index) : allele_index_(vector<size_t>(2))
50
50
{
51
51
  allele_index_[0] = first_allele_index;
52
52
  allele_index_[1] = second_allele_index;
53
53
}
54
54
 
55
 
BiAlleleMonolocusGenotype::BiAlleleMonolocusGenotype(std::vector<unsigned int> allele_index) throw (BadIntegerException): allele_index_(vector<unsigned int>(2))
 
55
BiAlleleMonolocusGenotype::BiAlleleMonolocusGenotype(std::vector<size_t> allele_index) throw (BadSizeException) : allele_index_(vector<size_t>(2))
56
56
{
57
57
  if (allele_index.size() != 2)
58
 
    throw BadIntegerException("BiAlleleMonolocusGenotype::BiAlleleMonolocusGenotype: allele_index must containes two values.", allele_index.size());
 
58
    throw BadSizeException("BiAlleleMonolocusGenotype::BiAlleleMonolocusGenotype: allele_index must contain two values.", allele_index.size(), 2);
59
59
  allele_index_[0] = allele_index[0];
60
60
  allele_index_[1] = allele_index[1];
61
61
}
62
62
 
63
 
BiAlleleMonolocusGenotype::BiAlleleMonolocusGenotype(const BiAlleleMonolocusGenotype& bmg): allele_index_(vector<unsigned int>(2))
 
63
BiAlleleMonolocusGenotype::BiAlleleMonolocusGenotype(const BiAlleleMonolocusGenotype& bmg) : allele_index_(vector<size_t>(2))
64
64
{
65
 
  for (unsigned int i=0 ; i<2 ; i++)
 
65
  for (size_t i = 0; i < 2; i++)
 
66
  {
66
67
    allele_index_[i] = bmg.getAlleleIndex()[i];
 
68
  }
67
69
}
68
70
 
69
 
//** Class destructor: ********************************************************/
 
71
// ** Class destructor: ********************************************************/
70
72
 
71
73
BiAlleleMonolocusGenotype::~BiAlleleMonolocusGenotype()
72
74
{
73
75
  allele_index_.clear();
74
76
}
75
77
 
76
 
//** Other methodes: **********************************************************/
 
78
// ** Other methodes: **********************************************************/
77
79
 
78
 
BiAlleleMonolocusGenotype& BiAlleleMonolocusGenotype::operator= (const BiAlleleMonolocusGenotype& bmg)
 
80
BiAlleleMonolocusGenotype& BiAlleleMonolocusGenotype::operator=(const BiAlleleMonolocusGenotype& bmg)
79
81
{
80
 
  for(unsigned int i = 0; i < 2; i++)
 
82
  for (size_t i = 0; i < 2; i++)
 
83
  {
81
84
    allele_index_.push_back(bmg.getAlleleIndex()[i]);
82
 
  return * this;
 
85
  }
 
86
  return *this;
83
87
}
84
88
 
85
 
bool BiAlleleMonolocusGenotype::operator== (const BiAlleleMonolocusGenotype& bmg) const
 
89
bool BiAlleleMonolocusGenotype::operator==(const BiAlleleMonolocusGenotype& bmg) const
86
90
{
87
 
  return ((allele_index_[0] == bmg.getAlleleIndex()[0] && allele_index_[1] == bmg.getAlleleIndex()[1])
88
 
      || (allele_index_[0] == bmg.getAlleleIndex()[1] && allele_index_[1] == bmg.getAlleleIndex()[0]));
 
91
  return (allele_index_[0] == bmg.getAlleleIndex()[0] && allele_index_[1] == bmg.getAlleleIndex()[1])
 
92
         || (allele_index_[0] == bmg.getAlleleIndex()[1] && allele_index_[1] == bmg.getAlleleIndex()[0]);
89
93
}
90
94
 
91
 
unsigned int BiAlleleMonolocusGenotype::getFirstAlleleIndex() const
 
95
size_t BiAlleleMonolocusGenotype::getFirstAlleleIndex() const
92
96
{
93
97
  return allele_index_[0];
94
98
}
95
99
 
96
 
unsigned int BiAlleleMonolocusGenotype::getSecondAlleleIndex() const
 
100
size_t BiAlleleMonolocusGenotype::getSecondAlleleIndex() const
97
101
{
98
102
  return allele_index_[1];
99
103
}
100
104
 
101
105
bool BiAlleleMonolocusGenotype::isHomozygous() const
102
106
{
103
 
  return (allele_index_[0] == allele_index_[1]);
 
107
  return allele_index_[0] == allele_index_[1];
104
108
}
105
109
 
106
 
std::vector<unsigned int> BiAlleleMonolocusGenotype::getAlleleIndex() const
 
110
std::vector<size_t> BiAlleleMonolocusGenotype::getAlleleIndex() const
107
111
{
108
112
  return allele_index_;
109
113
}
110
114
 
111
115
BiAlleleMonolocusGenotype* BiAlleleMonolocusGenotype::clone() const
112
116
{
113
 
  return new BiAlleleMonolocusGenotype(* this);
 
117
  return new BiAlleleMonolocusGenotype(*this);
114
118
}
115
119