]> git.donarmstrong.com Git - mothur.git/blobdiff - treemap.cpp
added sequence name to error string in fastq.info. Changed np_shannon to npshannon.
[mothur.git] / treemap.cpp
index bb624480e79640d8a23fc6fe4c47c8ba8c6b82a4..1fc5c01b796a67bd948a70147fa4dead9320ea08 100644 (file)
 /************************************************************/
 
  TreeMap::TreeMap(string filename) {
+       m = MothurOut::getInstance();
        groupFileName = filename;
-       openInputFile(filename, fileHandle);
+       m->openInputFile(filename, fileHandle);
 }
 
 /************************************************************/
  TreeMap::~TreeMap(){}
 
 /************************************************************/
-void TreeMap::readMap() {
+int TreeMap::readMap() {
                string seqName, seqGroup;
-       
+               int error = 0;
+               
                while(fileHandle){
-                       fileHandle >> seqName;                  //read from first column
+                       fileHandle >> seqName;          //read from first column
                        fileHandle >> seqGroup;                 //read from second column
                        
-                       namesOfSeqs.push_back(seqName);
-                       setNamesOfGroups(seqGroup);
-                                               
-                       treemap[seqName].groupname = seqGroup;  //store data in map
+                       if (m->control_pressed) {  fileHandle.close();  return 1; }
                        
-                       it2 = seqsPerGroup.find(seqGroup);
-                       if (it2 == seqsPerGroup.end()) { //if it's a new group
-                               seqsPerGroup[seqGroup] = 1;
-                       }else {//it's a group we already have
-                               seqsPerGroup[seqGroup]++;
+                       setNamesOfGroups(seqGroup);
+                                       
+                       map<string, GroupIndex>::iterator itCheck = treemap.find(seqName);
+                       if (itCheck != treemap.end()) { error = 1; m->mothurOut("[WARNING]: Your groupfile contains more than 1 sequence named " + seqName + ", sequence names must be unique. Please correct."); m->mothurOutEndLine();  }
+                       else {
+                               namesOfSeqs.push_back(seqName);
+                               treemap[seqName].groupname = seqGroup;  //store data in map
+                               
+                               it2 = seqsPerGroup.find(seqGroup);
+                               if (it2 == seqsPerGroup.end()) { //if it's a new group
+                                       seqsPerGroup[seqGroup] = 1;
+                               }else {//it's a group we already have
+                                       seqsPerGroup[seqGroup]++;
+                               }                               
                        }
-
-                       gobble(fileHandle);
+                       
+                       m->gobble(fileHandle);
                }
                fileHandle.close();
+       
+
+               return error;
+}
+/************************************************************/
+void TreeMap::addSeq(string seqName, string seqGroup) {
+       
+               namesOfSeqs.push_back(seqName);
+               setNamesOfGroups(seqGroup);
+                                       
+               treemap[seqName].groupname = seqGroup;  //store data in map
+                       
+               it2 = seqsPerGroup.find(seqGroup);
+               if (it2 == seqsPerGroup.end()) { //if it's a new group
+                       seqsPerGroup[seqGroup] = 1;
+               }else {//it's a group we already have
+                       seqsPerGroup[seqGroup]++;
+               }
 }
 /************************************************************/
 void TreeMap::removeSeq(string seqName) {
@@ -155,13 +181,13 @@ void TreeMap::print(ostream& output){
 }
 
 /************************************************************/
-void TreeMap::makeSim(GroupMap* groupmap) {
+void TreeMap::makeSim(vector<string> ThisnamesOfGroups) {
        try {
                //set names of groups
-               namesOfGroups = groupmap->namesOfGroups;
+               namesOfGroups = ThisnamesOfGroups;
                
                //set names of seqs to names of groups
-               namesOfSeqs = groupmap->namesOfGroups;
+               namesOfSeqs = ThisnamesOfGroups;
                
                // make map where key and value are both the group name since that what the tree.shared command wants
                for (int i = 0; i < namesOfGroups.size(); i++) {