5 * Created by Sarah Westcott on 1/26/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
12 /************************************************************/
14 TreeMap::TreeMap(string filename) {
15 groupFileName = filename;
16 openInputFile(filename, fileHandle);
19 /************************************************************/
20 TreeMap::~TreeMap(){};
22 /************************************************************/
23 void TreeMap::readMap() {
24 string seqName, seqGroup;
27 fileHandle >> seqName; //read from first column
28 fileHandle >> seqGroup; //read from second column
30 namesOfSeqs.push_back(seqName);
31 setNamesOfGroups(seqGroup);
33 treemap[seqName].groupname = seqGroup; //store data in map
39 /************************************************************/
41 int TreeMap::getNumGroups() {
43 return namesOfGroups.size();
46 /************************************************************/
48 int TreeMap::getNumSeqs() {
50 return namesOfSeqs.size();
54 /************************************************************/
56 string TreeMap::getGroup(string sequenceName) {
58 it = treemap.find(sequenceName);
59 if (it != treemap.end()) { //sequence name was in group file
60 return it->second.groupname;
66 /************************************************************/
67 void TreeMap::setIndex(string seq, int index) {
68 treemap[seq].vectorIndex = index;
70 /************************************************************/
71 int TreeMap::getIndex(string seq) {
73 it = treemap.find(seq);
74 // if it is a valid sequence name then return index
75 if (it != treemap.end()) { return treemap[seq].vectorIndex; }
76 // if not return error code
80 /************************************************************/
82 void TreeMap::setNamesOfGroups(string seqGroup) {
85 for (i=0; i<namesOfGroups.size(); i++) {
86 if (namesOfGroups[i] != seqGroup) {
87 count++; //you have not found this group
89 break; //you already have it
92 if (count == namesOfGroups.size()) {
93 namesOfGroups.push_back(seqGroup); //new group
97 /***********************************************************************/
99 void TreeMap::print(ostream& output){
102 for(it = treemap.begin(); it != treemap.end(); it++){
103 output << it->first << '\t' << it->second.groupname << '\t' << it->second.vectorIndex << endl;
106 catch(exception& e) {
107 cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
111 cout << "An unknown error has occurred in the TreeMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
116 /************************************************************/