| 1 |
/*************************************************************************** |
| 2 |
allele.cpp - description |
| 3 |
------------------- |
| 4 |
begin : Thu Sep 14 2000 |
| 5 |
copyright : (C) 2000 by Olivier Langella |
| 6 |
email : [email protected] |
| 7 |
***************************************************************************/ |
| 8 |
|
| 9 |
/*************************************************************************** |
| 10 |
* * |
| 11 |
* This program is free software; you can redistribute it and/or modify * |
| 12 |
* it under the terms of the GNU General Public License as published by * |
| 13 |
* the Free Software Foundation; either version 2 of the License, or * |
| 14 |
* (at your option) any later version. * |
| 15 |
* * |
| 16 |
***************************************************************************/ |
| 17 |
|
| 18 |
|
| 19 |
//#include "entetepop.h" |
| 20 |
#include "allele.h" |
| 21 |
#include "locus.h" |
| 22 |
|
| 23 |
//constructeur |
| 24 |
Allele::Allele (Locus* Ploc) |
| 25 |
{ |
| 26 |
_nom.assign(""); |
| 27 |
// strcpy (_nomgpop,_nom.c_str()); |
| 28 |
_Ploc = Ploc; |
| 29 |
|
| 30 |
_miss = r_ismissingvalue(_nom); |
| 31 |
// if ((_nom == "00") || (_nom == "NULL") || (_nom == "NULL") || (_nom == "NULL")) _nul = true; |
| 32 |
// else _nul = false; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
Allele::Allele (const Allele & original, Locus * Ploc) |
| 37 |
{ |
| 38 |
//constructeur de copies |
| 39 |
_nom.assign(original._nom); |
| 40 |
|
| 41 |
_Ploc = Ploc; |
| 42 |
_miss = original._miss; |
| 43 |
_nbrepet = original._nbrepet; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
Allele::Allele (Locus* Ploc,const string & nom) |
| 48 |
{ |
| 49 |
_nom = nom; |
| 50 |
// strcpy (_nomgpop,_nom.c_str()); |
| 51 |
_Ploc = Ploc; |
| 52 |
_nbrepet = atoi(nom.c_str()); |
| 53 |
|
| 54 |
_miss = r_ismissingvalue(nom); |
| 55 |
} |
| 56 |
|
| 57 |
Allele::Allele (Locus* Ploc,const char * nom) |
| 58 |
{ |
| 59 |
_nom.assign(nom); |
| 60 |
// strcpy (_nomgpop,_nom.c_str()); |
| 61 |
_Ploc = Ploc; |
| 62 |
_nbrepet = atoi(nom); |
| 63 |
|
| 64 |
_miss = r_ismissingvalue(nom); |
| 65 |
} |
| 66 |
|
| 67 |
//destructeur |
| 68 |
Allele::~Allele () |
| 69 |
{ |
| 70 |
// delete [] _tabPind; |
| 71 |
} |
| 72 |
|
| 73 |
bool Allele::f_verifnum(int typedenum) const |
| 74 |
{ |
| 75 |
// Vérification du type de numérotation des allèles |
| 76 |
// 1 => type Genepop stricte (2digits) |
| 77 |
// 2 => nom d'alleles = numéros |
| 78 |
// 3 => nom d'alleles = numéros < 999 |
| 79 |
//Anomalie 2-> les numéros d'allèles format genepop ne sont pas présents |
| 80 |
unsigned long i; |
| 81 |
|
| 82 |
switch (typedenum) |
| 83 |
{ |
| 84 |
case 1: |
| 85 |
if (_nom.size() != 2) return (false); |
| 86 |
if ((_nom[0] < 48) || ((_nom[0] > 57))) return (false); |
| 87 |
if ((_nom[1] < 48) || ((_nom[1] > 57))) return (false); |
| 88 |
|
| 89 |
break; |
| 90 |
case 2: |
| 91 |
for (i=0; i < _nom.size();i++) |
| 92 |
{ |
| 93 |
if ((_nom[i] < 48) || ((_nom[i] > 57))) return (false); |
| 94 |
} |
| 95 |
|
| 96 |
break; |
| 97 |
|
| 98 |
case 3: |
| 99 |
if (_nom.size() > 3) return (false); |
| 100 |
for (i=0; i < _nom.size();i++) |
| 101 |
{ |
| 102 |
if ((_nom[i] < 48) || ((_nom[i] > 57))) return (false); |
| 103 |
} |
| 104 |
|
| 105 |
break; |
| 106 |
} |
| 107 |
|
| 108 |
return(true); |
| 109 |
} |
| 110 |
|
| 111 |
const Allele& Allele::operator= (const Allele & rval) |
| 112 |
{ |
| 113 |
|
| 114 |
_nom = rval._nom; |
| 115 |
_miss = rval._miss; |
| 116 |
_nbrepet = rval._nbrepet; |
| 117 |
return(*this); |
| 118 |
} |
| 119 |
|
| 120 |
bool Allele::operator== (const Allele & rval) const |
| 121 |
{ |
| 122 |
//egalité basée sur les noms des allèles et des locus correspondants |
| 123 |
// PAS sur les pointeurs !!! |
| 124 |
if (rval._Ploc->get_nom() != _Ploc->get_nom()) return (false); |
| 125 |
|
| 126 |
return((_miss && rval._miss) || (rval._nom == _nom)); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
const string& Allele::get_NomLocus() const |
| 131 |
{ |
| 132 |
return(_Ploc->get_nom()); |
| 133 |
} |
| 134 |
|
| 135 |
bool Allele::r_ismissingvalue(const string & nom) const |
| 136 |
{ |
| 137 |
if ((nom == "0") || (nom == "000") || (nom == "00") || (nom == "null") || (nom == "NULL") || (nom == "miss") || (nom == "missing")) return true; |
| 138 |
else return false; |
| 139 |
} |
| 140 |
|