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 seqmap[name] = sequence;
30 it = data.find(sequence);
31 if (it == data.end()) { //it's unique.
32 data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found.
33 data[sequence].groupnumber = 1;
34 data[sequence].names = name;
35 }else { // its a duplicate.
36 data[sequence].names += "," + name;
37 data[sequence].groupnumber++;
39 name = (line.substr(1, (line.npos))); //The line you just read is a new name so rip off '>'
45 //store last sequence and name info.
46 seqmap[name] = sequence;
47 it = data.find(sequence);
48 if (it == data.end()) { //it's unique.
49 data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found.
50 data[sequence].groupnumber = 1;
51 data[sequence].names = name;
52 }else { // its a duplicate.
53 data[sequence].names += "," + name;
54 data[sequence].groupnumber++;
59 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
63 cout << "An unknown error has occurred in the FastaMap class function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
67 /*******************************************************************************/
68 string FastaMap::getGroupName(string seq) { //pass a sequence name get its group
69 return data[seq].groupname;
71 /*******************************************************************************/
72 string FastaMap::getNames(string seq) { //pass a sequence get the string of names in the group separated by ','s.
73 return data[seq].names;
75 /*******************************************************************************/
76 int FastaMap::getGroupNumber(string seq) { //pass a sequence get the number of identical sequences.
77 return data[seq].groupnumber;
79 /*******************************************************************************/
80 string FastaMap::getSequence(string name) {
81 it2 = seqmap.find(name);
82 if (it2 == seqmap.end()) { //it's not found
88 /*******************************************************************************/
89 void FastaMap::push_back(string name, string seq) {
91 if (it == data.end()) { //it's unique.
92 data[seq].groupname = name; //group name will be the name of the first duplicate sequence found.
93 data[seq].groupnumber = 1;
94 data[seq].names = name;
95 }else { // its a duplicate.
96 data[seq].names += "," + name;
97 data[seq].groupnumber++;
102 /*******************************************************************************/
103 int FastaMap::sizeUnique(){ //returns datas size which is the number of unique sequences
106 /*******************************************************************************/
107 void FastaMap::printNamesFile(ostream& out){ //prints data
109 // two column file created with groupname and them list of identical sequence names
110 for (it = data.begin(); it != data.end(); it++) {
111 out << it->second.groupname << '\t' << it->second.names << endl;
114 catch(exception& e) {
115 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
119 cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
123 /*******************************************************************************/
124 void FastaMap::printCondensedFasta(ostream& out){ //prints data
126 // two column file created with groupname and them list of identical sequence names
127 for (it = data.begin(); it != data.end(); it++) {
128 out << ">" << it->second.groupname << endl;
129 out << it->first << endl;
132 catch(exception& e) {
133 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
137 cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
141 /*******************************************************************************/