*/
#include "fastamap.h"
+#include "sequence.hpp"
/*******************************************************************************/
+
void FastaMap::readFastaFile(ifstream& in) {
try {
string name, sequence, line;
sequence = "";
-
- in >> line;
- name = line.substr(1, line.length()); //rips off '>'
-
+// int c;
+ string temp;
+
+
//read through file
- while (!in.eof()) {
- in >> line;
+// while ((c = in.get()) != EOF) {
+// name = ""; sequence = "";
+// //is this a name
+// if (c == '>') {
+// name = readName(in);
+// sequence = readSequence(in);
+// }else { cout << "Error fasta in your file. Please correct." << endl; }
- if (line[0] != '>') { //if it's a sequence line
- sequence += line;
- }
- else{
+ //store info in map
//input sequence info into map
- seqmap[name] = sequence;
-
- it = data.find(sequence);
- if (it == data.end()) { //it's unique.
- data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found.
- data[sequence].groupnumber = 1;
- data[sequence].names = name;
- }else { // its a duplicate.
- data[sequence].names += "," + name;
- data[sequence].groupnumber++;
- }
- name = (line.substr(1, (line.npos))); //The line you just read is a new name so rip off '>'
- sequence = "";
- }
+ while(!in.eof()){
+ Sequence currSeq(in);
+ name = currSeq.getName();
+ sequence = currSeq.getUnaligned();
+ seqmap[name] = sequence;
+ it = data.find(sequence);
+ if (it == data.end()) { //it's unique.
+ data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found.
+ data[sequence].groupnumber = 1;
+ data[sequence].names = name;
+ }else { // its a duplicate.
+ data[sequence].names += "," + name;
+ data[sequence].groupnumber++;
+ }
gobble(in);
}
- it = data.find(sequence);
- if (it == data.end()) { //it's unique.
- data[sequence].groupname = name; //group name will be the name of the first duplicate sequence found.
- data[sequence].groupnumber = 1;
- data[sequence].names = name;
- }else { // its a duplicate.
- data[sequence].names += "," + name;
- data[sequence].groupnumber++;
- }
-
-
+
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the FastaMap class Function readFastaFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
exit(1);
}
}
+
/*******************************************************************************/
+
string FastaMap::getGroupName(string seq) { //pass a sequence name get its group
return data[seq].groupname;
}
+
/*******************************************************************************/
+
string FastaMap::getNames(string seq) { //pass a sequence get the string of names in the group separated by ','s.
return data[seq].names;
}
+
/*******************************************************************************/
+
int FastaMap::getGroupNumber(string seq) { //pass a sequence get the number of identical sequences.
return data[seq].groupnumber;
}
+
/*******************************************************************************/
+
string FastaMap::getSequence(string name) {
it2 = seqmap.find(name);
if (it2 == seqmap.end()) { //it's not found
return it2->second;
}
}
+
/*******************************************************************************/
+
void FastaMap::push_back(string name, string seq) {
it = data.find(seq);
if (it == data.end()) { //it's unique.
seqmap[name] = seq;
}
+
/*******************************************************************************/
+
int FastaMap::sizeUnique(){ //returns datas size which is the number of unique sequences
return data.size();
}
+
/*******************************************************************************/
+
void FastaMap::printNamesFile(ostream& out){ //prints data
try {
// two column file created with groupname and them list of identical sequence names
exit(1);
}
}
+
/*******************************************************************************/
+
void FastaMap::printCondensedFasta(ostream& out){ //prints data
try {
- // two column file created with groupname and them list of identical sequence names
+ //creates a fasta file
for (it = data.begin(); it != data.end(); it++) {
out << ">" << it->second.groupname << endl;
out << it->first << endl;
exit(1);
}
}
+
/*******************************************************************************/