|
| 1 | +#include "Chromosome.h" |
| 2 | + |
| 3 | +std::map<std::string, int> Chromosome::chr_to_int; |
| 4 | +std::map<int, std::string> Chromosome::int_to_chr; |
| 5 | +std::map<std::string, int> Chromosome::scaffold_names; |
| 6 | + |
| 7 | +Chromosome::Chromosome(void) { |
| 8 | + this->name = "NA"; |
| 9 | +} |
| 10 | + |
| 11 | +Chromosome::Chromosome(std::string const & name) { |
| 12 | + this->name = name; |
| 13 | +} |
| 14 | + |
| 15 | +Chromosome::~Chromosome(void) { |
| 16 | + |
| 17 | +} |
| 18 | + |
| 19 | +std::map<std::string, int>& Chromosome::getChr_to_int(void) { |
| 20 | + return chr_to_int; |
| 21 | +} |
| 22 | + |
| 23 | +std::map<int, std::string>& Chromosome::getInt_to_chr(void) { |
| 24 | + return int_to_chr; |
| 25 | +} |
| 26 | + |
| 27 | +std::map<std::string, int>& Chromosome::getScaffold_names(void) { |
| 28 | + return scaffold_names; |
| 29 | +} |
| 30 | + |
| 31 | +std::string Chromosome::forValue(int const & value) { |
| 32 | + std::map<int, std::string>::iterator it = getInt_to_chr().find(value); |
| 33 | + if (it != getInt_to_chr().end()) { |
| 34 | + return it->second; |
| 35 | + } |
| 36 | + return "NA"; |
| 37 | +} |
| 38 | + |
| 39 | +int Chromosome::forName(std::string const & name) { |
| 40 | + std::map<std::string, int>::iterator it = getChr_to_int().find(name); |
| 41 | + if (it != getChr_to_int().end()) { |
| 42 | + return it->second; |
| 43 | + } |
| 44 | + return -1; |
| 45 | +} |
| 46 | + |
| 47 | +void Chromosome::addChr(std::string const & name) { |
| 48 | + std::string tmpname = name; |
| 49 | + std::string substring = tmpname.substr(0, 3); |
| 50 | + if (substring == "chr" || substring == "Chr") { |
| 51 | + tmpname = tmpname.substr(3); |
| 52 | + } |
| 53 | + std::map<std::string, int>::iterator it = getChr_to_int().find(tmpname); |
| 54 | + if (it == getChr_to_int().end()) |
| 55 | + { |
| 56 | + it = getScaffold_names().find(tmpname); |
| 57 | + if (it == getScaffold_names().end()) { |
| 58 | + int newrank = getChr_to_int().size() + 1; |
| 59 | + getChr_to_int().insert(std::pair<std::string, int>(tmpname, newrank)); |
| 60 | + getInt_to_chr().insert(std::pair<int, std::string>(newrank, tmpname)); |
| 61 | + if (tmpname == "M") { |
| 62 | + newrank = newrank + 1; |
| 63 | + getChr_to_int().insert(std::pair<std::string, int>("MT", newrank)); |
| 64 | + getInt_to_chr().insert(std::pair<int, std::string>(newrank, "MT")); |
| 65 | + } |
| 66 | + else if (tmpname == "MT") { |
| 67 | + newrank = newrank + 1; |
| 68 | + getChr_to_int().insert(std::pair<std::string, int>("M", newrank)); |
| 69 | + getInt_to_chr().insert(std::pair<int, std::string>(newrank, "M")); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +void Chromosome::addScaffold(std::string const & name) { |
| 76 | + std::map<std::string, int>::iterator it = getChr_to_int().find("scaffold"); |
| 77 | + if (it != getChr_to_int().end()) { |
| 78 | + int newrank = getChr_to_int().size() + 1; |
| 79 | + getChr_to_int().insert(std::pair<std::string, int>("scaffold", newrank)); |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +int Chromosome::getValue(void) const { |
| 84 | + std::map<std::string, int>::iterator it = getChr_to_int().find(name); |
| 85 | + if (it != getChr_to_int().end()) { |
| 86 | + return it->second; |
| 87 | + } |
| 88 | + return -1; |
| 89 | +} |
| 90 | + |
| 91 | +std::string Chromosome::getName(void) const { |
| 92 | + return name; |
| 93 | +} |
| 94 | + |
| 95 | +void Chromosome::setName(std::string const& name) { |
| 96 | + this->name = name; |
| 97 | +} |
| 98 | + |
| 99 | +bool Chromosome::isNA(void) const { |
| 100 | + return name == "NA"; |
| 101 | +} |
| 102 | + |
| 103 | +bool Chromosome::isScaffold(void) const { |
| 104 | + std::map<std::string, int>::iterator it = getScaffold_names().find(name); |
| 105 | + return it != getScaffold_names().end(); |
| 106 | +} |
0 commit comments