#include "chimera.h"
//***************************************************************************************************************
-//this is a vertical filter
+//this is a vertical soft filter
void Chimera::createFilter(vector<Sequence*> seqs) {
try {
-
+ filterString = "";
int threshold = int (0.5 * seqs.size());
//cout << "threshhold = " << threshold << endl;
}
}
+ //zero out spot where all sequences have blanks
//zero out spot where all sequences have blanks
int numColRemoved = 0;
for(int i = 0;i < seqs[0]->getAligned().length(); i++){
else if (((a[i] < threshold) && (t[i] < threshold) && (g[i] < threshold) && (c[i] < threshold))) { filterString[i] = '0'; numColRemoved++; }
//cout << "a = " << a[i] << " t = " << t[i] << " g = " << g[i] << " c = " << c[i] << endl;
}
+
//cout << "filter = " << filterString << endl;
mothurOut("Filter removed " + toString(numColRemoved) + " columns."); mothurOutEndLine();
}
}
//***************************************************************************************************************
-void Chimera::runFilter(vector<Sequence*> seqs) {
+void Chimera::runFilter(Sequence* seq) {
try {
- //for each sequence
- for (int i = 0; i < seqs.size(); i++) {
-
- string seqAligned = seqs[i]->getAligned();
- string newAligned = "";
-
- for (int j = 0; j < seqAligned.length(); j++) {
- //if this spot is a gap
- if (filterString[j] == '1') { newAligned += seqAligned[j]; }
- }
+ string seqAligned = seq->getAligned();
+ string newAligned = "";
- seqs[i]->setAligned(newAligned);
+ for (int j = 0; j < seqAligned.length(); j++) {
+ //if this spot is a gap
+ if (filterString[j] == '1') { newAligned += seqAligned[j]; }
}
-
+
+ seq->setAligned(newAligned);
}
catch(exception& e) {
errorOut(e, "Chimera", "runFilter");
exit(1);
}
}
-
//***************************************************************************************************************
vector<Sequence*> Chimera::readSeqs(string file) {
try {
+
+ mothurOut("Reading sequences... "); cout.flush();
ifstream in;
openInputFile(file, in);
vector<Sequence*> container;
+ int count = 0;
+ int length = 0;
+ unaligned = false;
//read in seqs and store in vector
while(!in.eof()){
- Sequence* current = new Sequence(in);
- container.push_back(current);
- gobble(in);
+ Sequence* current = new Sequence(in); gobble(in);
+
+ if (count == 0) { length = current->getAligned().length(); count++; } //gets first seqs length
+ else if (length != current->getAligned().length()) { //seqs are unaligned
+ unaligned = true;
+ }
+
+ if (current->getName() != "") { container.push_back(current); }
}
in.close();
+ mothurOut("Done."); mothurOutEndLine();
+
return container;
}
catch(exception& e) {
openInputFile(quanfile, in);
vector< vector<float> > quan;
- vector <float> temp;
+ vector <float> temp; temp.resize(6, 0);
//to fill 0
quan.push_back(temp);
}
}
//***************************************************************************************************************
+Sequence* Chimera::getSequence(string name) {
+ try{
+ Sequence* temp;
+
+ //look through templateSeqs til you find it
+ int spot = -1;
+ for (int i = 0; i < templateSeqs.size(); i++) {
+ if (name == templateSeqs[i]->getName()) {
+ spot = i;
+ break;
+ }
+ }
+
+ if(spot == -1) { mothurOut("Error: Could not find sequence."); mothurOutEndLine(); return NULL; }
+
+ temp = new Sequence(templateSeqs[spot]->getName(), templateSeqs[spot]->getAligned());
+
+ return temp;
+ }
+ catch(exception& e) {
+ errorOut(e, "Chimera", "getSequence");
+ exit(1);
+ }
+}
+//***************************************************************************************************************