-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSample.hpp
129 lines (121 loc) · 3.04 KB
/
Sample.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef genomic_Sample_h
#define genomic_Sample_h
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <stdexcept>
#include "typedefs.h"
#include "global.hpp"
#include "Chromosome.hpp"
#include "AlleleSpecific.hpp"
#include "Segment.hpp"
template <typename Chromosome>
class Sample
{
public:
typedef typename Chromosome::DataType T;
typedef std::vector<Chromosome> Chromosomes;
std::string name;
std::string platform;
private:
// vector of segments vectors for each Chromosome
Chromosomes items;
public:
Sample(const std::string& sampleName) : name(sampleName) {
// always allocate for all chromosomes
items.reserve(nChromosomes);
for (chromid i = 0; i < nChromosomes; ++i) {
items.push_back(Chromosome(i));
}
}
//Sample(const Sample& sample)
//: name(sample.name), platform(sample.platform), items(sample.items) {}
~Sample() {
clear();
}
void clear() {
items.clear();
}
const size_t size() const {
items.size();
}
Chromosome& at(chromid chromIndex) {
return this->operator[](chromIndex);
}
Chromosome& at(const std::string& chromName) {
return this->operator[](chromName);
}
Chromosome& operator[](chromid chromIndex) {
if (chromIndex < items.size()) {
return items[chromIndex];
} else {
throw logic_error("Chromosome index is out of bound.");
}
}
Chromosome& operator[](const std::string& chromName) {
chromid k = mapping::chromosome[chromName];
if (k != 0) return items[k-1];
throw logic_error("Chromosome name is not found.");
}
typename Chromosomes::iterator begin() {
return items.begin();
}
typename Chromosomes::iterator end() {
return items.end();
}
typename Chromosomes::const_iterator begin() const {
return items.begin();
}
typename Chromosomes::const_iterator end() const {
return items.end();
}
Chromosome* chromosome(chromid chromIndex) {
if (chromIndex < items.size()) {
return &(items[chromIndex]);
}
return NULL;
}
Chromosome* chromosome(const std::string& chromName) {
chromid k = mapping::chromosome[chromName];
if (k != 0) return &(items[k-1]);
return NULL;
}
T* addToChromosome(chromid chromIndex, const T& item) {
if (chromIndex < items.size()) {
Chromosome& chrom = items[chromIndex];
chrom.push_back(item);
return &(chrom[ chrom.size() - 1 ]);
}
return NULL;
}
T* addToChromosome(const std::string& chromName, const T& item) {
chromid k = mapping::chromosome[chromName];
if (k != 0) {
Chromosome& chrom = items[k-1];
chrom.push_back(item);
return &(chrom[ chrom.size() - 1 ]);
}
return NULL;
}
void resizeChromosome(chromid chromIndex, size_t n) {
if (chromIndex < items.size()) {
items[chromIndex].resize(n);
}
}
void remove(T item) {
throw logic_error("Sample::remove(T) has yet been implemented.");
// not implemented
// need to find segment in data structure
}
static bool compare(const Sample& a, const Sample& b) {
return a.name < b.name;
}
static bool pcompare(Sample* a, Sample* b) {
return a->name < b->name;
}
};
#endif