5 * Created by Sarah Westcott on 1/16/09.
6 * Copyright 2009 Schloss Lab UMASS AMherst. All rights reserved.
12 /*******************************************************************************/
13 void FastaMap::readFastaFile(ifstream& in) {
15 string name, sequence, line;
19 name = line.substr(1, line.length()); //rips off '>'
22 while (getline(in, line)) {
24 if (isalnum(line.at(0))) { //if it's a sequence line
28 //input sequence info into map
29 it = data.find(sequence);
30 if (it == data.end()) { //it's unique.
31 data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found.
32 data[sequence].groupnumber = 1;
33 data[sequence].names = name;
34 }else { // its a duplicate.
35 data[sequence].names += "," + name;
36 data[sequence].groupnumber++;
38 name = (line.substr(1, (line.npos))); //The line you just read is a new name so rip off '>'
44 //store last sequence and name info.
45 it = data.find(sequence);
46 if (it == data.end()) { //it's unique.
47 data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found.
48 data[sequence].groupnumber = 1;
49 data[sequence].names = name;
50 }else { // its a duplicate.
51 data[sequence].names += "," + name;
52 data[sequence].groupnumber++;
56 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
60 cout << "An unknown error has occurred in the FastaMap class function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
64 /*******************************************************************************/
65 string FastaMap::getGroupName(string seq) { //pass a sequence name get its group
66 return data[seq].groupname;
68 /*******************************************************************************/
69 string FastaMap::getNames(string seq) { //pass a sequence get the string of names in the group separated by ','s.
70 return data[seq].names;
72 /*******************************************************************************/
73 int FastaMap::getGroupNumber(string seq) { //pass a sequence get the number of identical sequences.
74 return data[seq].groupnumber;
76 /*******************************************************************************/
77 void FastaMap::push_back(string seq, string Name) {//sequencename, name
78 data[seq].groupname = Name;
79 data[seq].names = Name;
81 /*******************************************************************************/
82 void FastaMap::set(string seq, string groupName, string Names) {
83 data[seq].groupname = groupName;
84 data[seq].names = Names;
86 /*******************************************************************************/
87 void FastaMap::clear() { //clears out data
90 /*******************************************************************************/
91 int FastaMap::size(){ //returns datas size which is the number of unique sequences
94 /*******************************************************************************/
95 void FastaMap::print(ostream& out){ //prints data
97 // two column file created with groupname and them list of identical sequence names
98 for (it = data.begin(); it != data.end(); it++) {
99 out << it->second.groupname << '\t' << it->second.names << endl;
102 catch(exception& e) {
103 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
107 cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
111 /*******************************************************************************/
112 void FastaMap::printCondensedFasta(ostream& out){ //prints data
114 // two column file created with groupname and them list of identical sequence names
115 for (it = data.begin(); it != data.end(); it++) {
116 out << ">" << it->second.groupname << endl;
117 out << it->first << endl;
120 catch(exception& e) {
121 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
125 cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
129 /*******************************************************************************/