37D928840F21331F001D4494 /* sabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9281A0F21331F001D4494 /* sabundvector.cpp */; };
37D928850F21331F001D4494 /* sequence.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9281C0F21331F001D4494 /* sequence.cpp */; };
37D928860F21331F001D4494 /* shannon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D9281E0F21331F001D4494 /* shannon.cpp */; };
- 37D928870F21331F001D4494 /* shared.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928200F21331F001D4494 /* shared.cpp */; };
37D928880F21331F001D4494 /* sharedace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928220F21331F001D4494 /* sharedace.cpp */; };
37D928890F21331F001D4494 /* sharedchao1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928240F21331F001D4494 /* sharedchao1.cpp */; };
37D9288A0F21331F001D4494 /* sharedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D928260F21331F001D4494 /* sharedcommand.cpp */; };
37D9281D0F21331F001D4494 /* sequence.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = sequence.hpp; sourceTree = SOURCE_ROOT; };
37D9281E0F21331F001D4494 /* shannon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = shannon.cpp; sourceTree = SOURCE_ROOT; };
37D9281F0F21331F001D4494 /* shannon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shannon.h; sourceTree = SOURCE_ROOT; };
- 37D928200F21331F001D4494 /* shared.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = shared.cpp; sourceTree = SOURCE_ROOT; };
- 37D928210F21331F001D4494 /* shared.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shared.h; sourceTree = SOURCE_ROOT; };
37D928220F21331F001D4494 /* sharedace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedace.cpp; sourceTree = SOURCE_ROOT; };
37D928230F21331F001D4494 /* sharedace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedace.h; sourceTree = SOURCE_ROOT; };
37D928240F21331F001D4494 /* sharedchao1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedchao1.cpp; sourceTree = SOURCE_ROOT; };
37D928050F21331F001D4494 /* rarefact.cpp */,
37D928090F21331F001D4494 /* rarefactioncurvedata.h */,
3796441D0FB9B9650081FDB6 /* read */,
- 37D928210F21331F001D4494 /* shared.h */,
- 37D928200F21331F001D4494 /* shared.cpp */,
211C38310F961DD400FEE541 /* sharedutilities.h */,
211C38300F961DD400FEE541 /* sharedutilities.cpp */,
37D928420F21331F001D4494 /* singlelinkage.cpp */,
37D928840F21331F001D4494 /* sabundvector.cpp in Sources */,
37D928850F21331F001D4494 /* sequence.cpp in Sources */,
37D928860F21331F001D4494 /* shannon.cpp in Sources */,
- 37D928870F21331F001D4494 /* shared.cpp in Sources */,
37D928880F21331F001D4494 /* sharedace.cpp in Sources */,
37D928890F21331F001D4494 /* sharedchao1.cpp in Sources */,
37D9288A0F21331F001D4494 /* sharedcommand.cpp in Sources */,
string iters;
};
-/***********************************************************************/
+
#endif
globaldata = GlobalData::getInstance();
//read in group map info.
- groupMap = new GroupMap(globaldata->getGroupFile());
- groupMap->readMap();
+ //groupMap = new GroupMap(globaldata->getGroupFile());
+ //groupMap->readMap();
+ groupMap = globaldata->gGroupmap;
//fill filehandles with neccessary ofstreams
int i;
ofstream* temp;
+ SharedListVector* templist;
for (i=0; i<groupMap->getNumGroups(); i++) {
temp = new ofstream;
+ templist = new SharedListVector();
filehandles[groupMap->namesOfGroups[i]] = temp;
+ mapOfLists[groupMap->namesOfGroups[i]] = templist;
}
//set fileroot
fileroot = getRootName(globaldata->getListFile());
- //open output list files
- for (i=0; i<groupMap->getNumGroups(); i++) {//opens an output file for each group
+ //clears file before we start to write to it below
+ for (int i=0; i<groupMap->getNumGroups(); i++) {
openOutputFile(fileroot + groupMap->namesOfGroups[i] + ".list", *(filehandles[groupMap->namesOfGroups[i]]));
+ (*(filehandles[groupMap->namesOfGroups[i]])).close();
}
+
+
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the ParseListCommand class Function ParseListCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
/***********************************************************************/
void ParseListCommand::parse(int index, SharedListVector* list) {
try {
- string prefix, suffix, groupsName;
- suffix = list->get(index);
-
- while (suffix.find_first_of(',') != -1) {//while you still have sequences
- prefix = suffix.substr(0,suffix.find_first_of(','));
- if ((suffix.find_first_of(',')+1) <= suffix.length()) { //checks to make sure you don't have comma at end of string
- suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
+ string member, bin, groupName;
+ bin = list->get(index);
+
+ while (bin.find_first_of(',') != -1) {//while you still have sequences
+ member = bin.substr(0,bin.find_first_of(','));
+ if ((bin.find_first_of(',')+1) <= bin.length()) { //checks to make sure you don't have comma at end of string
+ bin = bin.substr(bin.find_first_of(',')+1, bin.length());
}
- groupsName = groupMap->getGroup(prefix);
- if (groupsName != "not found") {
- listGroups[groupsName] = listGroups[groupsName] + "," + prefix; //adds prefix to the correct group.
+ groupName = groupMap->getGroup(member);
+ if (groupName != "not found") {
+ listGroups[groupName] = listGroups[groupName] + "," + member; //adds prefix to the correct group.
}else {
- cerr << "Error: Sequence '" << prefix << "' was not found in the group file, please correct\n";
+ cerr << "Error: Sequence '" << member << "' was not found in the group file, please correct\n";
}
}
//save last name after comma
- groupsName = groupMap->getGroup(suffix);
- if (groupsName != "not found") {
- listGroups[groupsName] = listGroups[groupsName] + "," + suffix; //adds prefix to the correct group.
+ groupName = groupMap->getGroup(bin);
+ if (groupName != "not found") {
+ listGroups[groupName] = listGroups[groupName] + "," + bin; //adds prefix to the correct group.
}else {
- cerr << "Error: Sequence '" << suffix << "' was not found in the group file, please correct\n";
+ cerr << "Error: Sequence '" << bin << "' was not found in the group file, please correct\n";
}
}
catch(exception& e) {
int ParseListCommand::execute(){
try{
+
int count = 1;
//read in listfile
set<string> userLabels = globaldata->labels;
set<int> userLines = globaldata->lines;
- //create new list vectors to fill with parsed data
- for (int i=0; i<groupMap->getNumGroups(); i++) {
- groupOfLists[groupMap->namesOfGroups[i]] = new SharedListVector();
- }
-
-
//parses and sets each groups listvector
//as long as you are not at the end of the file or done wih the lines you want
while((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
cout << lastList->getLabel() << '\t' << count << endl;
process(lastList);
}
- delete lastList;
-
- //set groupmap for .shared commands
- if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; }
- globaldata->gGroupmap = groupMap;
-
- //close files
- for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
- ofstream* temp = it3->second;
- (*temp).close();
- delete it3->second;
- }
+ delete lastList; globaldata->gSharedList = NULL;
//delete list vectors to fill with parsed data
- for (it2 = groupOfLists.begin(); it2 != groupOfLists.end(); it2++) {
+ for (it2 = mapOfLists.begin(); it2 != mapOfLists.end(); it2++) {
+ delete it2->second;
+ }
+ for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
delete it2->second;
}
+
+ delete input; globaldata->ginput = NULL;
+ delete read;
+
return 0;
}
catch(exception& e) {
//**********************************************************************************************************************
ParseListCommand::~ParseListCommand(){
-
- globaldata->gSharedList = NULL;
- delete input; globaldata->ginput = NULL;
- delete read;
-
+
+
}
//**********************************************************************************************************************
void ParseListCommand::process(SharedListVector* thisList) {
for (it=listGroups.begin(); it != listGroups.end(); it++) { //loop through map and set new list vectors
seq = it->second;
seq = seq.substr(1, seq.length()); //rips off extra comma
- groupOfLists[it->first]->push_back(seq); //sets new listvector for each group
+ mapOfLists[it->first]->push_back(seq); //sets new listvector for each group
}
listGroups.clear();
}
//prints each new list file
for (int i=0; i<groupMap->getNumGroups(); i++) {
- groupOfLists[groupMap->namesOfGroups[i]]->setLabel(thisList->getLabel());
- groupOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]]));
- groupOfLists[groupMap->namesOfGroups[i]]->clear();
+ openOutputFileAppend(fileroot + groupMap->namesOfGroups[i] + ".list", *(filehandles[groupMap->namesOfGroups[i]]));
+ mapOfLists[groupMap->namesOfGroups[i]]->setLabel(thisList->getLabel());
+ mapOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]]));
+ mapOfLists[groupMap->namesOfGroups[i]]->clear();
+ (*(filehandles[groupMap->namesOfGroups[i]])).close();
}
}
InputData* input;
ReadOTUFile* read;
map<string, ofstream*> filehandles;
- map<string, SharedListVector*> groupOfLists;
+ map<string, SharedListVector*> mapOfLists;
SharedListVector* list;
map<string, string> listGroups; //maps group name to sequences from that group in a specific OTU
map<string, string>::iterator it;
+++ /dev/null
-/*
- * shared.cpp
- * Dotur
- *
- * Created by Sarah Westcott on 12/5/08.
- * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
- *
- */
-
-#include "shared.h"
-
-/**************************************************************************************************/
-
-Shared::Shared(){
- globaldata = GlobalData::getInstance();
-}
-
-/**************************************************************************************************/
-void Shared::getSharedVectors(SharedListVector* list) {
- string label, group;
- int i,j;
- label = list->getLabel();
-
- for (it = sharedGroups.begin(); it != sharedGroups.end(); it++) { delete it->second; }
- sharedGroups.clear(); //removes old info.
-
- //initalize sharedGroups
- for (j=0; j<globaldata->gGroupmap->getNumGroups(); j++) {//for each group
- group = globaldata->gGroupmap->namesOfGroups[j];
- sharedGroups[group] = new SharedRAbundVector();
- sharedGroups[group]->setLabel(label);
- for (i = 0; i<list->size(); i++) { //for each otu
- sharedGroups[group]->push_back(0, i, group); //initialize to 0.
- }
- }
-
- //fills sharedGroups
- for (i = 0; i<list->size(); i++) {
- parse(i, list);
- }
-
- //updates sharedVector
- //sharedRAbund.push_back(sharedGroups);
-}
-
-
-
-/***********************************************************************/
-void Shared::parse(int index, SharedListVector* list) {
-
- string prefix, suffix, groupsName;
- suffix = list->get(index);
-
- while (suffix.find_first_of(',') != -1) {//while you still have sequences
- prefix = suffix.substr(0,suffix.find_first_of(','));
- if ((suffix.find_first_of(',')+1) <= suffix.length()) { //checks to make sure you don't have comma at end of string
- suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
- }
- groupsName = globaldata->gGroupmap->getGroup(prefix);
- if (groupsName != "not found") {
- sharedGroups[groupsName]->set(index, (sharedGroups[groupsName]->getAbundance(index) + 1), groupsName); //increment shared vector for that group
- }else {
- cerr << "Error: Sequence '" << prefix << "' was not found in the group file, please correct\n";
- }
- }
-
- //save last name after comma
- groupsName = globaldata->gGroupmap->getGroup(suffix);
- if (groupsName != "not found") {
- sharedGroups[groupsName]->set(index, ((sharedGroups[groupsName]->getAbundance(index)) + 1), groupsName); //increment shared vector for that group
- }else {
- cerr << "Error: Sequence '" << suffix << "' was not found in the group file, please correct\n";
- }
- }
+++ /dev/null
-#ifndef SHARED_H
-#define SHARED_H
-
-/*
- * shared.h
- * Dotur
- *
- * Created by Sarah Westcott on 12/5/08.
- * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
- *
- */
-
-#include "mothur.h"
-#include "sharedrabundvector.h"
-#include "sharedlistvector.h"
-#include "globaldata.hpp"
-
-class Shared {
- public:
- Shared();
- ~Shared() {};
- void getSharedVectors(SharedListVector*);
- map<string, SharedRAbundVector*> sharedGroups; //string is groupname, SharedVector* is out info for that group
-
- private:
- GlobalData* globaldata;
- map<string, SharedRAbundVector*>::iterator it;
- void parse(int, SharedListVector*);
- //vector< map<string, SharedRAbundVector*> > sharedRAbund; //contains all the info needed to create the .shared file not sure if we will need
-};
-
-#endif
int SharedCommand::execute(){
try {
- globaldata = GlobalData::getInstance();
+
+ cout << "creating sharedfile...";
//lookup.clear();
int count = 1;
string errorOff = "no error";
input = globaldata->ginput;
SharedList = globaldata->gSharedList;
SharedListVector* lastList = SharedList;
- //lookup = SharedList->getSharedRAbundVector();
- //vector<SharedRAbundVector*> lastLookup = lookup;
-
+ vector<SharedRAbundVector*> lookup;
+
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
set<string> processedLabels;
set<string> userLabels = globaldata->labels;
set<int> userLines = globaldata->lines;
- shared = new Shared();
while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
-
- shared->getSharedVectors(SharedList); //fills sharedGroups with new info and updates sharedVector
- printSharedData(); //prints info to the .shared file
+ lookup = SharedList->getSharedRAbundVector();
+ printSharedData(lookup); //prints info to the .shared file
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
processedLabels.insert(SharedList->getLabel());
userLabels.erase(SharedList->getLabel());
}
if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
- shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
- printSharedData(); //prints info to the .shared file
-
+ lookup = lastList->getSharedRAbundVector();
+ printSharedData(lookup); //prints info to the .shared file
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+
processedLabels.insert(lastList->getLabel());
userLabels.erase(lastList->getLabel());
}
if (count != 1) { delete lastList; }
- lastList = SharedList;
+ lastList = SharedList;
+
SharedList = input->getSharedListVector(); //get new list vector to process
- count++;
- //if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } }
- //lastLookup = lookup;
- //if (SharedList != NULL) { lookup = SharedList->getSharedRAbundVector(); }
+ count++;
}
//output error messages about any remaining user labels
//run last line if you need to
if (needToRun == true) {
- shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
- printSharedData(); //prints info to the .shared file
+ lookup = lastList->getSharedRAbundVector();
+ printSharedData(lookup); //prints info to the .shared file
+ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
+
}
delete lastList; globaldata->gSharedList = NULL;
- delete shared;
+ delete read;
+
out.close();
+ cout << "complete." << endl;
return 0;
}
catch(exception& e) {
}
//**********************************************************************************************************************
-void SharedCommand::printSharedData() {
+void SharedCommand::printSharedData(vector<SharedRAbundVector*> thislookup) {
try {
-
- ///for (int i = 0; i < thislookup.size(); i++) {
- // out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
-//cout << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << endl;
- // thislookup[i]->print(out);
- // }
- //prints out horizontally
- for (it = shared->sharedGroups.begin(); it != shared->sharedGroups.end(); it++) {
- out << it->second->getLabel() << "\t" << it->first << "\t"; //prints out label and groupname
- it->second->print(out); // prints sharedrabundvector
+
+ //initialize bin values
+ for (int i = 0; i < thislookup.size(); i++) {
+ out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
+ thislookup[i]->print(out);
}
+
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
SharedCommand::~SharedCommand(){
//delete list;
- delete read;
+
}
#include "command.hpp"
#include "sharedlistvector.h"
#include "inputdata.h"
-#include "shared.h"
#include "readotu.h"
/* The shared() command:
void help() {}
private:
- void printSharedData();
+ void printSharedData(vector<SharedRAbundVector*>);
GlobalData* globaldata;
ReadOTUFile* read;
SharedListVector* SharedList;
InputData* input;
- Shared* shared;
- map<string, SharedRAbundVector*>::iterator it;
+ //map<string, SharedRAbundVector*>::iterator it;
//vector<SharedRAbundVector*> lookup;
ofstream out;
string filename;
+ bool firsttime;
};
/***********************************************************************/
-SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance();}
+SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; }
/***********************************************************************/
-SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance();}
+SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; }
/***********************************************************************/
SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
SharedUtil* util;
util = new SharedUtil();
vector<SharedRAbundVector*> lookup;
+ map<string, SharedRAbundVector*> finder;
+ string group, names, name;
util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups);
delete util;
for (int i = 0; i < globaldata->Groups.size(); i++) {
- SharedRAbundVector* temp = new SharedRAbundVector();
- *temp = getSharedRAbundVector(globaldata->Groups[i]);
- lookup.push_back(temp);
+ SharedRAbundVector* temp = new SharedRAbundVector(data.size());
+ finder[globaldata->Groups[i]] = temp;
+ finder[globaldata->Groups[i]]->setLabel(label);
+ finder[globaldata->Groups[i]]->setGroup(globaldata->Groups[i]);
+ //*temp = getSharedRAbundVector(globaldata->Groups[i]);
+ lookup.push_back(finder[globaldata->Groups[i]]);
}
-
+
+ //fill vectors
+ for(int i=0;i<numBins;i++){
+ names = get(i);
+ while (names.find_first_of(',') != -1) {
+ name = names.substr(0,names.find_first_of(','));
+ names = names.substr(names.find_first_of(',')+1, names.length());
+ group = groupmap->getGroup(name);
+ finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in
+ }
+
+ //get last name
+ group = groupmap->getGroup(names);
+ finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in
+
+ }
+
return lookup;
}
catch(exception& e) {
SharedListVector();
SharedListVector(int);
SharedListVector(ifstream&);
- SharedListVector(const SharedListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs){globaldata = GlobalData::getInstance();};
- ~SharedListVector(){};
+ SharedListVector(const SharedListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs){globaldata = GlobalData::getInstance(); groupmap = NULL; };
+ ~SharedListVector(){ if (groupmap != NULL) { delete groupmap; } };
int getNumBins() { return numBins; }
int getNumSeqs() { return numSeqs; }