File: groupmap.h

package info (click to toggle)
mothur 1.48.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,676 kB
  • sloc: cpp: 161,854; makefile: 119; sh: 31
file content (81 lines) | stat: -rwxr-xr-x 3,587 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef GROUPMAP_H
#define GROUPMAP_H
/*
 *  groupmap.h
 *  Mothur
 *
 *  Created by Sarah Westcott on 12/1/08.
 *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
 *
 */

#include "mothur.h"
#include "mothurout.h"
#include "utils.hpp"

/* This class is a representation of the groupfile.  It is used by all the shared commands to determine what group a 
	certain sequence belongs to. */

class GroupMap {
public:
	GroupMap() { m = MothurOut::getInstance(); groupFileName = ""; }
	GroupMap(string);
	~GroupMap();
    
    int getCopy(GroupMap*);
    
    int readMap();
	int readMap(vector<string> groups); //selected groups read in. If groups.size() == 0, all groups are read
    int readMap(string, vector<string> groups); //filename, selected groups. selected groups read in. If groups.size() == 0, all groups are read
    int readMap(string);
	int readDesignMap();
    int readDesignMap(string);
    
	int getNumGroups();
	bool isValidGroup(string);  //return true if string is a valid group
	string getGroup(string);
    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.
    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.
    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.
    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.
    
	void setGroup(string, string);
	vector<string> getNamesOfGroups() {
		sort(namesOfGroups.begin(), namesOfGroups.end());
		groupIndex.clear();
		for (int i = 0; i < namesOfGroups.size(); i++) { groupIndex[namesOfGroups[i]] = i; }
		return namesOfGroups;
	}
    
    void removeGroups(vector<string> groups);
    
    vector<string> getNamesSeqs();
    vector<string> getNamesSeqs(string); //get names of seqs belonging to group passed in
    vector<string> getNamesSeqs(vector<string>); //get names of seqs belonging to the set of groups passed in
	void setNamesOfGroups(vector<string> sn) { namesOfGroups = sn; }
	int getNumSeqs()  {  return (int)groupmap.size();  }
    int getNumSeqs(string); //return the number of seqs in a given group
    int getNumSeqsSmallestGroup(); //returns size of smallest group
	
    int renameSeq(string, string);
    int addSeq(string name, string group);
    
    int print(string);
    int print(ofstream&);
    int print(ofstream&, vector<string>); //print certain groups
    
    map<string, int> groupIndex;  //groupname, vectorIndex in namesOfGroups. - used by collectdisplays and libshuff commands.
    
private:
	vector<string> namesOfGroups;
	MothurOut* m;
	string groupFileName;
    int index;
	map<string, string>::iterator it;
	void setNamesOfGroups(string); 
	map<string, string> groupmap; //sequence name and groupname
	map<string, int> seqsPerGroup;  //maps groupname to number of seqs in that group
    Utils util;
};

#endif