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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
/*
* order.cpp
*
*
* Created by Pat Schloss on 8/8/08.
* Copyright 2008 Patrick D. Schloss. All rights reserved.
*
*/
#include "ordervector.hpp"
/***********************************************************************/
OrderVector::OrderVector() : DataVector() {}
/***********************************************************************/
//OrderVector::OrderVector(int ns) : DataVector(), data(ns, -1) {}
/***********************************************************************/
OrderVector::OrderVector(string id, vector<int> ov) :
DataVector(id), data(ov)
{
updateStats();
}
/***********************************************************************/
OrderVector::OrderVector(ifstream& f) : DataVector() {
try {
int hold;
f >> label;
f >> hold;
data.assign(hold, -1);
int inputData;
for(int i=0;i<hold;i++){
f >> inputData;
set(i, inputData);
}
updateStats();
}
catch(exception& e) {
m->errorOut(e, "OrderVector", "OrderVector");
exit(1);
}
}
/***********************************************************************/
int OrderVector::getNumBins(){
if(needToUpdate == 1){ updateStats(); }
return numBins;
}
/***********************************************************************/
int OrderVector::getNumSeqs(){
if(needToUpdate == 1){ updateStats(); }
return numSeqs;
}
/***********************************************************************/
int OrderVector::getMaxRank(){
if(needToUpdate == 1){ updateStats(); }
return maxRank;
}
/***********************************************************************/
void OrderVector::clear(){
numBins = 0;
maxRank = 0;
numSeqs = 0;
data.clear();
}
/***********************************************************************/
void OrderVector::set(int index, int binNumber){
data[index] = binNumber;
needToUpdate = 1;
}
/***********************************************************************/
int OrderVector::get(int index){
return data[index];
}
/***********************************************************************/
void OrderVector::push_back(int index){
data.push_back(index);
needToUpdate = 1;
}
/***********************************************************************/
void OrderVector::print(ostream& output){
try {
output << label << '\t' << numSeqs << '\t';
for(int i=0;i<data.size();i++){
output << data[i] << '\t';
}
output << endl;
}
catch(exception& e) {
m->errorOut(e, "OrderVector", "print");
exit(1);
}
}
/***********************************************************************/
void OrderVector::print(string prefix, ostream& output){
try {
output << prefix << '\t' << numSeqs << '\t';
for(int i=0;i<numSeqs;i++){
output << data[i] << '\t';
}
output << endl;
}
catch(exception& e) {
m->errorOut(e, "OrderVector", "print");
exit(1);
}
}
/***********************************************************************/
void OrderVector::resize(int){
m->mothurOut("resize() did nothing in class OrderVector");
}
/***********************************************************************/
int OrderVector::size(){
return data.size();
}
/***********************************************************************/
vector<int>::iterator OrderVector::begin(){
return data.begin();
}
/***********************************************************************/
vector<int>::iterator OrderVector::end(){
return data.end();
}
/***********************************************************************/
RAbundVector OrderVector::getRAbundVector(){
try {
RAbundVector rav(data.size());
for(int i=0;i<numSeqs;i++){
rav.set(data[i], rav.get(data[i]) + 1);
}
sort(rav.rbegin(), rav.rend());
for(int i=numSeqs-1;i>=0;i--){
if(rav.get(i) == 0){ rav.pop_back(); }
else{
break;
}
}
rav.setLabel(label);
return rav;
}
catch(exception& e) {
m->errorOut(e, "OrderVector", "getRAbundVector");
exit(1);
}
}
/***********************************************************************/
SAbundVector OrderVector::getSAbundVector(){
RAbundVector rav(this->getRAbundVector());
return rav.getSAbundVector();
}
/***********************************************************************/
OrderVector OrderVector::getOrderVector(map<string,int>* hold = 0){
return *this;
}
/***********************************************************************/
void OrderVector::updateStats(){
try {
needToUpdate = 0;
// int maxBinVectorLength = 0;
numSeqs = 0;
numBins = 0;
maxRank = 0;
for(int i=0;i<data.size();i++){
if(data[i] != -1){
numSeqs++;
}
}
vector<int> hold(numSeqs);
for(int i=0;i<numSeqs;i++){
if(data[i] != -1){
hold[data[i]] = hold[data[i]]+1;
}
}
for(int i=0;i<numSeqs;i++){
if(hold[i] > 0) { numBins++; }
if(hold[i] > maxRank) { maxRank = hold[i]; }
}
}
catch(exception& e) {
m->errorOut(e, "OrderVector", "updateStats");
exit(1);
}
}
/***********************************************************************/
|