5 * Created by Thomas Ryabin on 4/13/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "sequencedb.h"
11 #include "sequence.hpp"
13 #include "calculator.h"
16 /***********************************************************************/
18 SequenceDB::SequenceDB() {}
19 /***********************************************************************/
20 //the clear function free's the memory
21 SequenceDB::~SequenceDB() { clear(); }
23 /***********************************************************************/
25 SequenceDB::SequenceDB(int newSize) {
26 data.resize(newSize, Sequence());
29 /***********************************************************************/
31 SequenceDB::SequenceDB(ifstream& filehandle) {
33 string name, sequence, line;
40 while ((c = filehandle.get()) != EOF) {
41 name = ""; sequence = "";
44 name = readName(filehandle);
45 sequence = readSequence(filehandle);
46 }else { cout << "Error fasta in your file. Please correct." << endl; }
48 //input sequence info into sequencedb
49 Sequence newSequence(name, sequence);
50 data.push_back(newSequence);
52 //takes care of white space
60 cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function SequenceDB. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
64 cout << "An unknown error has occurred in the SequenceDB class function SequenceDB. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
68 /*******************************************************************************/
69 string SequenceDB::readName(ifstream& in) {
75 while ((c = in.get()) != EOF) {
76 //if c is not a line return
85 cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function readName. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
89 cout << "An unknown error has occurred in the SequenceDB class function readName. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
94 /*******************************************************************************/
95 string SequenceDB::readSequence(ifstream& in) {
102 //save position in file in case next line is a new name.
106 //if you are at a new name
107 if (line[0] == '>') {
108 //put file pointer back since you are now at a new name
109 in.seekg(pos, ios::beg);
110 c = in.get(); //because you put it back to a newline char
112 }else { sequence += line; }
117 catch(exception& e) {
118 cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function readSequence. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
122 cout << "An unknown error has occurred in the SequenceDB class function readSequence. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
127 /***********************************************************************/
129 int SequenceDB::getNumSeqs() {
133 /***********************************************************************/
135 void SequenceDB::set(int index, string newUnaligned) {
137 data[index] = Sequence(data[index].getName(), newUnaligned);
139 catch(exception& e) {
140 cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
144 cout << "An unknown error has occurred in the SequenceDB class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
149 /***********************************************************************/
151 void SequenceDB::set(int index, Sequence newSeq) {
153 data[index] = newSeq;
155 catch(exception& e) {
156 cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
160 cout << "An unknown error has occurred in the SequenceDB class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
165 /***********************************************************************/
167 Sequence SequenceDB::get(int index) {
171 /***********************************************************************/
173 void SequenceDB::resize(int newSize) {
175 data.resize(newSize);
177 catch(exception& e) {
178 cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function resize. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
182 cout << "An unknown error has occurred in the SequenceDB class function resize. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
187 /***********************************************************************/
189 void SequenceDB::clear() {
193 catch(exception& e) {
194 cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
198 cout << "An unknown error has occurred in the SequenceDB class function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
203 /***********************************************************************/
205 int SequenceDB::size() {
209 /***********************************************************************/
211 void SequenceDB::print(ostream& out) {
213 for(int i = 0; i < data.size(); i++) {
214 data[i].printSequence(out);
217 catch(exception& e) {
218 cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
222 cout << "An unknown error has occurred in the SequenceDB class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
227 /***********************************************************************/
229 void SequenceDB::push_back(Sequence newSequence) {
231 data.push_back(newSequence);
233 catch(exception& e) {
234 cout << "Standard Error: " << e.what() << " has occurred in the SequenceDB class Function add. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
238 cout << "An unknown error has occurred in the SequenceDB class function add. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
243 /***********************************************************************/