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;
22 while ((c = in.get()) != EOF) {
23 name = ""; sequence = "";
27 sequence = readSequence(in);
28 }else { cout << "Error fasta in your file. Please correct." << endl; }
31 //input sequence info into map
32 seqmap[name] = sequence;
33 it = data.find(sequence);
34 if (it == data.end()) { //it's unique.
35 data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found.
36 data[sequence].groupnumber = 1;
37 data[sequence].names = name;
38 }else { // its a duplicate.
39 data[sequence].names += "," + name;
40 data[sequence].groupnumber++;
48 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
52 cout << "An unknown error has occurred in the FastaMap class function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
56 /*******************************************************************************/
57 string FastaMap::readName(ifstream& in) {
63 while ((c = in.get()) != EOF) {
64 //if c is not a line return
73 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function readName. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
77 cout << "An unknown error has occurred in the FastaMap class function readName. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82 /*******************************************************************************/
83 string FastaMap::readSequence(ifstream& in) {
90 //save position in file in case next line is a new name.
94 //if you are at a new name
96 //put file pointer back since you are now at a new name
97 in.seekg(pos, ios::beg);
98 c = in.get(); //because you put it back to a newline char
100 }else { sequence += line; }
105 catch(exception& e) {
106 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function readSequence. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
110 cout << "An unknown error has occurred in the FastaMap class function readSequence. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
114 /*******************************************************************************/
115 string FastaMap::getGroupName(string seq) { //pass a sequence name get its group
116 return data[seq].groupname;
118 /*******************************************************************************/
119 string FastaMap::getNames(string seq) { //pass a sequence get the string of names in the group separated by ','s.
120 return data[seq].names;
122 /*******************************************************************************/
123 int FastaMap::getGroupNumber(string seq) { //pass a sequence get the number of identical sequences.
124 return data[seq].groupnumber;
126 /*******************************************************************************/
127 string FastaMap::getSequence(string name) {
128 it2 = seqmap.find(name);
129 if (it2 == seqmap.end()) { //it's not found
135 /*******************************************************************************/
136 void FastaMap::push_back(string name, string seq) {
138 if (it == data.end()) { //it's unique.
139 data[seq].groupname = name; //group name will be the name of the first duplicate sequence found.
140 data[seq].groupnumber = 1;
141 data[seq].names = name;
142 }else { // its a duplicate.
143 data[seq].names += "," + name;
144 data[seq].groupnumber++;
149 /*******************************************************************************/
150 int FastaMap::sizeUnique(){ //returns datas size which is the number of unique sequences
153 /*******************************************************************************/
154 void FastaMap::printNamesFile(ostream& out){ //prints data
156 // two column file created with groupname and them list of identical sequence names
157 for (it = data.begin(); it != data.end(); it++) {
158 out << it->second.groupname << '\t' << it->second.names << endl;
161 catch(exception& e) {
162 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
166 cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
170 /*******************************************************************************/
171 void FastaMap::printCondensedFasta(ostream& out){ //prints data
173 //creates a fasta file
174 for (it = data.begin(); it != data.end(); it++) {
175 out << ">" << it->second.groupname << endl;
176 out << it->first << endl;
179 catch(exception& e) {
180 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
184 cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
188 /*******************************************************************************/