#include <fstream>
/*******************************************************************************/
-ReadFasta::ReadFasta(string file) : ReadSeqs(file) {
- try {
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the ReadTree class Function ReadTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the ReadTree class function ReadTree. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-}
+ReadFasta::ReadFasta(string file) : ReadSeqs(file) {}
/*******************************************************************************/
ReadFasta::~ReadFasta(){
//for(int i = 0; i < sequencedb.getNumSeqs(); i++)
}
/*******************************************************************************/
void ReadFasta::read() {
- string name = "";
+ try {
+ /*string name = "";
string sequence = "";
string temp;
int count = 0;
}
Sequence newSequence(name, sequence);
- sequencedb.add(newSequence);
+ sequencedb.add(newSequence); */
+
+ string name, sequence, line;
+ sequence = "";
+ int c;
+ string temp;
+
+
+ //read through file
+ while ((c = filehandle.get()) != EOF) {
+ name = ""; sequence = "";
+ //is this a name
+ if (c == '>') {
+ name = readName(filehandle);
+ sequence = readSequence(filehandle);
+ }else { cout << "Error fasta in your file. Please correct." << endl; }
- filehandle.close();
+ //input sequence info into sequencedb
+ Sequence newSequence(name, sequence);
+ sequencedb.add(newSequence);
+
+ //takes care of white space
+ gobble(filehandle);
+ }
+
+ filehandle.close();
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the ReadFasta class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the ReadFasta class function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
}
/*********************************************************************************/
SequenceDB* ReadFasta::getDB() {
return &sequencedb;
}
+/*******************************************************************************/
+string ReadFasta::readName(ifstream& in) {
+ try{
+ string name = "";
+ int c;
+ string temp;
+
+ while ((c = in.get()) != EOF) {
+ //if c is not a line return
+ if (c != 10) {
+ name += c;
+ }else { break; }
+ }
+
+ return name;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the ReadFasta class Function readName. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the ReadFasta class function readName. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+
+/*******************************************************************************/
+string ReadFasta::readSequence(ifstream& in) {
+ try{
+ string sequence = "";
+ string line;
+ int pos, c;
+
+ while (!in.eof()) {
+ //save position in file in case next line is a new name.
+ pos = in.tellg();
+ line = "";
+ in >> line;
+ //if you are at a new name
+ if (line[0] == '>') {
+ //put file pointer back since you are now at a new name
+ in.seekg(pos, ios::beg);
+ c = in.get(); //because you put it back to a newline char
+ break;
+ }else { sequence += line; }
+ }
+
+ return sequence;
+ }
+ catch(exception& e) {
+ cout << "Standard Error: " << e.what() << " has occurred in the ReadFasta class Function readSequence. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+ catch(...) {
+ cout << "An unknown error has occurred in the ReadFasta class function readSequence. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+ exit(1);
+ }
+}
+/*******************************************************************************/
+