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 '>'
25 if (isalnum(line.at(0))) { //if it's a sequence line
29 //input sequence info into map
30 seqmap[name] = sequence;
31 it = data.find(sequence);
32 if (it == data.end()) { //it's unique.
33 data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found.
34 data[sequence].groupnumber = 1;
35 data[sequence].names = name;
36 }else { // its a duplicate.
37 data[sequence].names += "," + name;
38 data[sequence].groupnumber++;
40 name = (line.substr(1, (line.npos))); //The line you just read is a new name so rip off '>'
50 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54 cout << "An unknown error has occurred in the FastaMap class function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
58 /*******************************************************************************/
59 string FastaMap::getGroupName(string seq) { //pass a sequence name get its group
60 return data[seq].groupname;
62 /*******************************************************************************/
63 string FastaMap::getNames(string seq) { //pass a sequence get the string of names in the group separated by ','s.
64 return data[seq].names;
66 /*******************************************************************************/
67 int FastaMap::getGroupNumber(string seq) { //pass a sequence get the number of identical sequences.
68 return data[seq].groupnumber;
70 /*******************************************************************************/
71 string FastaMap::getSequence(string name) {
72 it2 = seqmap.find(name);
73 if (it2 == seqmap.end()) { //it's not found
79 /*******************************************************************************/
80 void FastaMap::push_back(string name, string seq) {
82 if (it == data.end()) { //it's unique.
83 data[seq].groupname = name; //group name will be the name of the first duplicate sequence found.
84 data[seq].groupnumber = 1;
85 data[seq].names = name;
86 }else { // its a duplicate.
87 data[seq].names += "," + name;
88 data[seq].groupnumber++;
93 /*******************************************************************************/
94 int FastaMap::sizeUnique(){ //returns datas size which is the number of unique sequences
97 /*******************************************************************************/
98 void FastaMap::printNamesFile(ostream& out){ //prints data
100 // two column file created with groupname and them list of identical sequence names
101 for (it = data.begin(); it != data.end(); it++) {
102 out << it->second.groupname << '\t' << it->second.names << endl;
105 catch(exception& e) {
106 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
110 cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
114 /*******************************************************************************/
115 void FastaMap::printCondensedFasta(ostream& out){ //prints data
117 // two column file created with groupname and them list of identical sequence names
118 for (it = data.begin(); it != data.end(); it++) {
119 out << ">" << it->second.groupname << endl;
120 out << it->first << 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";
132 /*******************************************************************************/