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
35 it2 = seqsPerGroup.find(seqGroup);
36 if (it2 == seqsPerGroup.end()) { //if it's a new group
37 seqsPerGroup[seqGroup] = 1;
38 }else {//it's a group we already have
39 seqsPerGroup[seqGroup]++;
46 /************************************************************/
48 int TreeMap::getNumGroups() {
50 return namesOfGroups.size();
53 /************************************************************/
55 int TreeMap::getNumSeqs() {
57 return namesOfSeqs.size();
61 /************************************************************/
63 string TreeMap::getGroup(string sequenceName) {
65 it = treemap.find(sequenceName);
66 if (it != treemap.end()) { //sequence name was in group file
67 return it->second.groupname;
73 /************************************************************/
74 void TreeMap::setIndex(string seq, int index) {
75 treemap[seq].vectorIndex = index;
77 /************************************************************/
78 int TreeMap::getIndex(string seq) {
80 it = treemap.find(seq);
81 // if it is a valid sequence name then return index
82 if (it != treemap.end()) { return treemap[seq].vectorIndex; }
83 // if not return error code
87 /************************************************************/
89 void TreeMap::setNamesOfGroups(string seqGroup) {
92 for (i=0; i<namesOfGroups.size(); i++) {
93 if (namesOfGroups[i] != seqGroup) {
94 count++; //you have not found this group
96 break; //you already have it
99 if (count == namesOfGroups.size()) {
100 namesOfGroups.push_back(seqGroup); //new group
103 /************************************************************/
104 bool TreeMap::isValidGroup(string groupname) {
106 for (int i = 0; i < namesOfGroups.size(); i++) {
107 if (groupname == namesOfGroups[i]) { return true; }
112 catch(exception& e) {
113 cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
117 cout << "An unknown error has occurred in the TreeMap class function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
121 /***********************************************************************/
123 void TreeMap::print(ostream& output){
126 for(it = treemap.begin(); it != treemap.end(); it++){
127 output << it->first << '\t' << it->second.groupname << '\t' << it->second.vectorIndex << endl;
130 catch(exception& e) {
131 cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
135 cout << "An unknown error has occurred in the TreeMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
140 /************************************************************/