/***********************************************************************/
SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
try {
+ groupmap = NULL; countTable = NULL;
//set up groupmap for later.
if (m->groupMode == "group") {
groupmap = new GroupMap(m->getGroupFile());
groupmap->readMap();
}else {
countTable = new CountTable();
- countTable->readTable(m->getCountTableFile());
+ countTable->readTable(m->getCountTableFile(), true, false);
}
- int hold;
- string inputData;
- f >> label >> hold;
-
- data.assign(hold, "");
+ int hold;
+
+ //are we at the beginning of the file??
+ if (m->saveNextLabel == "") {
+ f >> label;
+
+ //is this a shared file that has headers
+ if (label == "label") {
+
+ //gets "numOtus"
+ f >> label; m->gobble(f);
+
+ //eat rest of line
+ label = m->getline(f); m->gobble(f);
+
+ //parse labels to save
+ istringstream iStringStream(label);
+ m->listBinLabelsInFile.clear();
+ while(!iStringStream.eof()){
+ if (m->control_pressed) { break; }
+ string temp;
+ iStringStream >> temp; m->gobble(iStringStream);
+
+ m->listBinLabelsInFile.push_back(temp);
+ }
+
+ f >> label >> hold;
+ }else {
+ //read in first row
+ f >> hold;
+
+ //make binlabels because we don't have any
+ string snumBins = toString(hold);
+ m->listBinLabelsInFile.clear();
+ for (int i = 0; i < hold; i++) {
+ //if there is a bin label use it otherwise make one
+ string binLabel = "Otu";
+ string sbinNumber = toString(i+1);
+ if (sbinNumber.length() < snumBins.length()) {
+ int diff = snumBins.length() - sbinNumber.length();
+ for (int h = 0; h < diff; h++) { binLabel += "0"; }
+ }
+ binLabel += sbinNumber;
+ m->listBinLabelsInFile.push_back(binLabel);
+ }
+ }
+ m->saveNextLabel = label;
+ }else {
+ f >> label >> hold;
+ m->saveNextLabel = label;
+ }
+
+ binLabels.assign(m->listBinLabelsInFile.begin(), m->listBinLabelsInFile.begin()+hold);
+ data.assign(hold, "");
+ string inputData = "";
+
for(int i=0;i<hold;i++){
f >> inputData;
set(i, inputData);
}
+ m->gobble(f);
+
+ if (f.eof()) { m->saveNextLabel = ""; }
}
catch(exception& e) {
string SharedListVector::get(int index){
return data[index];
}
+/***********************************************************************/
+
+void SharedListVector::setLabels(vector<string> labels){
+ try {
+ binLabels = labels;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SharedListVector", "setLabels");
+ exit(1);
+ }
+}
+/***********************************************************************/
+//could potentially end up with duplicate binlabel names with code below.
+//we don't currently use them in a way that would do that.
+//if you had a listfile that had been subsampled and then added to it, dup names would be possible.
+vector<string> SharedListVector::getLabels(){
+ try {
+ string tagHeader = "Otu";
+ if (m->sharedHeaderMode == "tax") { tagHeader = "PhyloType"; }
+
+ if (binLabels.size() < data.size()) {
+ string snumBins = toString(numBins);
+
+ for (int i = 0; i < numBins; i++) {
+ string binLabel = tagHeader;
+
+ if (i < binLabels.size()) { //label exists, check leading zeros length
+ string sbinNumber = m->getSimpleLabel(binLabels[i]);
+ if (sbinNumber.length() < snumBins.length()) {
+ int diff = snumBins.length() - sbinNumber.length();
+ for (int h = 0; h < diff; h++) { binLabel += "0"; }
+ }
+ binLabel += sbinNumber;
+ binLabels[i] = binLabel;
+ }else{
+ string sbinNumber = toString(i+1);
+ if (sbinNumber.length() < snumBins.length()) {
+ int diff = snumBins.length() - sbinNumber.length();
+ for (int h = 0; h < diff; h++) { binLabel += "0"; }
+ }
+ binLabel += sbinNumber;
+ binLabels.push_back(binLabel);
+ }
+ }
+ }
+ return binLabels;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SharedListVector", "getLabels");
+ exit(1);
+ }
+}
/***********************************************************************/
void SharedListVector::push_back(string seqNames){
/***********************************************************************/
SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) {
try {
+ m->currentSharedBinLabels = binLabels;
+
SharedRAbundVector rav(data.size());
for(int i=0;i<numBins;i++){
/***********************************************************************/
vector<SharedRAbundVector*> SharedListVector::getSharedRAbundVector() {
try {
+ m->currentSharedBinLabels = binLabels;
+
SharedUtil* util;
util = new SharedUtil();
vector<SharedRAbundVector*> lookup; //contains just the groups the user selected