1 #ifndef GROUPMAP_H 2 #define GROUPMAP_H 3 /* 4 * groupmap.h 5 * Mothur 6 * 7 * Created by Sarah Westcott on 12/1/08. 8 * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved. 9 * 10 */ 11 12 #include "mothur.h" 13 #include "mothurout.h" 14 #include "utils.hpp" 15 16 /* This class is a representation of the groupfile. It is used by all the shared commands to determine what group a 17 certain sequence belongs to. */ 18 19 class GroupMap { 20 public: GroupMap()21 GroupMap() { m = MothurOut::getInstance(); groupFileName = ""; } 22 GroupMap(string); 23 ~GroupMap(); 24 25 int getCopy(GroupMap*); 26 27 int readMap(); 28 int readMap(vector<string> groups); //selected groups read in. If groups.size() == 0, all groups are read 29 int readMap(string, vector<string> groups); //filename, selected groups. selected groups read in. If groups.size() == 0, all groups are read 30 int readMap(string); 31 int readDesignMap(); 32 int readDesignMap(string); 33 34 int getNumGroups(); 35 bool isValidGroup(string); //return true if string is a valid group 36 string getGroup(string); 37 vector<string> getGroups(string); //returns groups represented by the seqs passed in. Think column two from a namefile row (seq1,seq2,seq3,seq4,seq5) -> (group1,group2). seqs1,seq3 are from group1, seq2,seq4,seq5 are from group2. 38 vector<string> getGroups(vector<string>); //returns groups represented by the seqs passed in. Think column two from a namefile row (seq1,seq2,seq3,seq4,seq5) stored as a vector of names -> (group1,group2). seqs1,seq3 are from group1, seq2,seq4,seq5 are from group2. 39 int getNumSeqs(string, string); //list of seq names, group. returns number of seqs from group passed represented by the seqs passed in. Think column two from a namefile row (seq1,seq2,seq3,seq4,seq5), group1 -> 2. seqs1,seq3 are from group1, seq2,seq4,seq5 are from group2. 40 int getNumSeqs(vector<string>, string); //vector of seq names, group. returns number of seqs from group passed represented by the seqs passed in. Think column two from a namefile row (seq1,seq2,seq3,seq4,seq5), group1 -> 2. seqs1,seq3 are from group1, seq2,seq4,seq5 are from group2. 41 42 void setGroup(string, string); getNamesOfGroups()43 vector<string> getNamesOfGroups() { 44 sort(namesOfGroups.begin(), namesOfGroups.end()); 45 groupIndex.clear(); 46 for (int i = 0; i < namesOfGroups.size(); i++) { groupIndex[namesOfGroups[i]] = i; } 47 return namesOfGroups; 48 } 49 50 void removeGroups(vector<string> groups); 51 52 vector<string> getNamesSeqs(); 53 vector<string> getNamesSeqs(string); //get names of seqs belonging to group passed in 54 vector<string> getNamesSeqs(vector<string>); //get names of seqs belonging to the set of groups passed in setNamesOfGroups(vector<string> sn)55 void setNamesOfGroups(vector<string> sn) { namesOfGroups = sn; } getNumSeqs()56 int getNumSeqs() { return (int)groupmap.size(); } 57 int getNumSeqs(string); //return the number of seqs in a given group 58 int getNumSeqsSmallestGroup(); //returns size of smallest group 59 60 int renameSeq(string, string); 61 int addSeq(string name, string group); 62 63 int print(string); 64 int print(ofstream&); 65 int print(ofstream&, vector<string>); //print certain groups 66 67 map<string, int> groupIndex; //groupname, vectorIndex in namesOfGroups. - used by collectdisplays and libshuff commands. 68 69 private: 70 vector<string> namesOfGroups; 71 MothurOut* m; 72 string groupFileName; 73 int index; 74 map<string, string>::iterator it; 75 void setNamesOfGroups(string); 76 map<string, string> groupmap; //sequence name and groupname 77 map<string, int> seqsPerGroup; //maps groupname to number of seqs in that group 78 Utils util; 79 }; 80 81 #endif 82