5 * Created by Sarah Westcott on 1/16/09.
6 * Copyright 2009 Schloss Lab UMASS AMherst. All rights reserved.
11 #include "sequence.hpp"
13 /*******************************************************************************/
15 void FastaMap::readFastaFile(ifstream& in) {
17 string name, sequence, line;
24 // while ((c = in.get()) != EOF) {
25 // name = ""; sequence = "";
28 // name = readName(in);
29 // sequence = readSequence(in);
30 // }else { cout << "Error fasta in your file. Please correct." << endl; }
33 //input sequence info into map
36 name = currSeq.getName();
37 sequence = currSeq.getUnaligned();
38 seqmap[name] = sequence;
39 it = data.find(sequence);
40 if (it == data.end()) { //it's unique.
41 data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found.
42 data[sequence].groupnumber = 1;
43 data[sequence].names = name;
44 }else { // its a duplicate.
45 data[sequence].names += "," + name;
46 data[sequence].groupnumber++;
54 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
58 cout << "An unknown error has occurred in the FastaMap class function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
63 /*******************************************************************************/
65 string FastaMap::getGroupName(string seq) { //pass a sequence name get its group
66 return data[seq].groupname;
69 /*******************************************************************************/
71 string FastaMap::getNames(string seq) { //pass a sequence get the string of names in the group separated by ','s.
72 return data[seq].names;
75 /*******************************************************************************/
77 int FastaMap::getGroupNumber(string seq) { //pass a sequence get the number of identical sequences.
78 return data[seq].groupnumber;
81 /*******************************************************************************/
83 string FastaMap::getSequence(string name) {
84 it2 = seqmap.find(name);
85 if (it2 == seqmap.end()) { //it's not found
92 /*******************************************************************************/
94 void FastaMap::push_back(string name, string seq) {
96 if (it == data.end()) { //it's unique.
97 data[seq].groupname = name; //group name will be the name of the first duplicate sequence found.
98 data[seq].groupnumber = 1;
99 data[seq].names = name;
100 }else { // its a duplicate.
101 data[seq].names += "," + name;
102 data[seq].groupnumber++;
108 /*******************************************************************************/
110 int FastaMap::sizeUnique(){ //returns datas size which is the number of unique sequences
114 /*******************************************************************************/
116 void FastaMap::printNamesFile(ostream& out){ //prints data
118 // two column file created with groupname and them list of identical sequence names
119 for (it = data.begin(); it != data.end(); it++) {
120 out << it->second.groupname << '\t' << it->second.names << endl;
123 catch(exception& e) {
124 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
128 cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
133 /*******************************************************************************/
135 void FastaMap::printCondensedFasta(ostream& out){ //prints data
137 //creates a fasta file
138 for (it = data.begin(); it != data.end(); it++) {
139 out << ">" << it->second.groupname << endl;
140 out << it->first << endl;
143 catch(exception& e) {
144 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
148 cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
153 /*******************************************************************************/