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(string inFileName) {
18 openInputFile(inFileName, in);
19 string name, sequence, line;
25 name = currSeq.getName();
27 if(currSeq.getIsAligned()) { sequence = currSeq.getAligned(); }
28 else { sequence = currSeq.getUnaligned(); }
30 seqmap[name] = sequence;
31 map<string,group>::iterator 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++;
46 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
50 cout << "An unknown error has occurred in the FastaMap class function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
55 /*******************************************************************************/
57 void FastaMap::readFastaFile(string inFastaFile, string oldNameFileName){ //prints data
60 openInputFile(oldNameFileName, oldNameFile);
62 map<string,string> oldNameMap;
64 while(!oldNameFile.eof()){
65 oldNameFile >> name >> list;
66 oldNameMap[name] = list;
72 openInputFile(inFastaFile, inFASTA);
74 while(!inFASTA.eof()){
75 Sequence currSeq(inFASTA);
76 name = currSeq.getName();
78 if(currSeq.getIsAligned()) { sequence = currSeq.getAligned(); }
79 else { sequence = currSeq.getUnaligned(); }
81 seqmap[name] = sequence;
82 map<string,group>::iterator it = data.find(sequence);
83 if (it == data.end()) { //it's unique.
84 data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found.
85 // data[sequence].groupnumber = 1;
86 data[sequence].names = oldNameMap[name];
87 }else { // its a duplicate.
88 data[sequence].names += "," + oldNameMap[name];
89 // data[sequence].groupnumber++;
99 /*******************************************************************************/
101 string FastaMap::getGroupName(string seq) { //pass a sequence name get its group
102 return data[seq].groupname;
105 /*******************************************************************************/
107 string FastaMap::getNames(string seq) { //pass a sequence get the string of names in the group separated by ','s.
108 return data[seq].names;
111 /*******************************************************************************/
113 string FastaMap::getSequence(string name) {
115 map<string,string>::iterator it = seqmap.find(name);
116 if (it == seqmap.end()) { return "not found"; }
117 else { return it->second; }
121 /*******************************************************************************/
123 void FastaMap::push_back(string name, string seq) {
125 map<string,group>::iterator it = data.find(seq);
126 if (it == data.end()) { //it's unique.
127 data[seq].groupname = name; //group name will be the name of the first duplicate sequence found.
128 data[seq].names = name;
129 }else { // its a duplicate.
130 data[seq].names += "," + name;
135 /*******************************************************************************/
137 int FastaMap::sizeUnique(){ //returns datas size which is the number of unique sequences
141 /*******************************************************************************/
143 void FastaMap::printNamesFile(string outFileName){ //prints data
146 openOutputFile(outFileName, outFile);
148 // two column file created with groupname and them list of identical sequence names
149 for (map<string,group>::iterator it = data.begin(); it != data.end(); it++) {
150 outFile << it->second.groupname << '\t' << it->second.names << endl;
154 catch(exception& e) {
155 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
159 cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
164 /*******************************************************************************/
166 void FastaMap::printCondensedFasta(string outFileName){ //prints data
169 openOutputFile(outFileName, out);
170 //creates a fasta file
171 for (map<string,group>::iterator it = data.begin(); it != data.end(); it++) {
172 out << ">" << it->second.groupname << endl;
173 out << it->first << endl;
177 catch(exception& e) {
178 cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
182 cout << "An unknown error has occurred in the FastaMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
187 /*******************************************************************************/