]> git.donarmstrong.com Git - mothur.git/blobdiff - groupmap.cpp
removed read.dist, read.otu, read.tree and globaldata. added current to defaults...
[mothur.git] / groupmap.cpp
index 8d0662f9c404cb05d4cfed74596a33284d5235d9..58e04c5db858791f28a99a5cb50795a570da0690 100644 (file)
@@ -14,7 +14,7 @@
  GroupMap::GroupMap(string filename) {
        m = MothurOut::getInstance();
        groupFileName = filename;
-       openInputFile(filename, fileHandle);
+       m->openInputFile(filename, fileHandle);
        index = 0;
 }
 
 int GroupMap::readMap() {
                string seqName, seqGroup;
                int error = 0;
-       
+
                while(fileHandle){
-                       fileHandle >> seqName;                  //read from first column
+                       fileHandle >> seqName;  m->gobble(fileHandle);          //read from first column
                        fileHandle >> seqGroup;                 //read from second column
                        
+                       if (m->control_pressed) {  fileHandle.close();  return 1; }
+       
                        setNamesOfGroups(seqGroup);
                        
                        it = groupmap.find(seqName);
@@ -39,11 +41,39 @@ int GroupMap::readMap() {
                                groupmap[seqName] = seqGroup;   //store data in map
                                seqsPerGroup[seqGroup]++;  //increment number of seqs in that group
                        }
-                       gobble(fileHandle);
+                       m->gobble(fileHandle);
+               }
+               fileHandle.close();
+               m->namesOfGroups = namesOfGroups;
+               return error;
+}
+/************************************************************/
+int GroupMap::readDesignMap() {
+               string seqName, seqGroup;
+               int error = 0;
+
+               while(fileHandle){
+                       fileHandle >> seqName;  m->gobble(fileHandle);          //read from first column
+                       fileHandle >> seqGroup;                 //read from second column
+                       
+                       if (m->control_pressed) {  fileHandle.close();  return 1; }
+       
+                       setNamesOfGroups(seqGroup);
+                       
+                       it = groupmap.find(seqName);
+                       
+                       if (it != groupmap.end()) { error = 1; m->mothurOut("Your designfile contains more than 1 group named " + seqName + ", group names must be unique. Please correct."); m->mothurOutEndLine();  }
+                       else {
+                               groupmap[seqName] = seqGroup;   //store data in map
+                               seqsPerGroup[seqGroup]++;  //increment number of seqs in that group
+                       }
+                       m->gobble(fileHandle);
                }
                fileHandle.close();
+               m->namesOfGroups = namesOfGroups;
                return error;
 }
+
 /************************************************************/
 int GroupMap::getNumGroups() { return namesOfGroups.size();    }
 /************************************************************/
@@ -59,26 +89,28 @@ string GroupMap::getGroup(string sequenceName) {
 }
 
 /************************************************************/
+
 void GroupMap::setGroup(string sequenceName, string groupN) {
        groupmap[sequenceName] = groupN;
 }
+
 /************************************************************/
 void GroupMap::setNamesOfGroups(string seqGroup) {
-                       int i, count;
-                       count = 0;
-                       for (i=0; i<namesOfGroups.size(); i++) {
-                               if (namesOfGroups[i] != seqGroup) {
-                                       count++; //you have not found this group
-                               }else {
-                                       break; //you already have it
-                               }
-                       }
-                       if (count == namesOfGroups.size()) {
-                               namesOfGroups.push_back(seqGroup); //new group
-                               seqsPerGroup[seqGroup] = 0;
-                               groupIndex[seqGroup] = index;
-                               index++;
-                       }
+       int i, count;
+       count = 0;
+       for (i=0; i<namesOfGroups.size(); i++) {
+               if (namesOfGroups[i] != seqGroup) {
+                       count++; //you have not found this group
+               }else {
+                       break; //you already have it
+               }
+       }
+       if (count == namesOfGroups.size()) {
+               namesOfGroups.push_back(seqGroup); //new group
+               seqsPerGroup[seqGroup] = 0;
+               groupIndex[seqGroup] = index;
+               index++;
+       }
 }
 /************************************************************/
 bool GroupMap::isValidGroup(string groupname) {
@@ -131,4 +163,25 @@ vector<string> GroupMap::getNamesSeqs(){
        }
 }
 /************************************************************/
+vector<string> GroupMap::getNamesSeqs(vector<string> picked){
+       try {
+               
+               vector<string> names;
+               
+               for (it = groupmap.begin(); it != groupmap.end(); it++) {
+                       //if you are belong to one the the groups in the picked vector add you
+                       if (m->inUsersGroups(it->second, picked)) {
+                               names.push_back(it->first);
+                       }
+               }
+               
+               return names;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GroupMap", "getNamesSeqs");
+               exit(1);
+       }
+}
+
+/************************************************************/