2 * filterseqscommand.cpp
5 * Created by Thomas Ryabin on 5/4/09.
6 * Copyright 2009 __MyCompanyName__. All rights reserved.
10 #include "filterseqscommand.h"
14 /**************************************************************************************/
15 void FilterSeqsCommand::doTrump() {
16 trump = globaldata->getTrump();
17 for(int i = 0; i < db->size(); i++) {
18 Sequence cur = db->get(i);
19 string curAligned = cur.getAligned();
20 for(int j = 0; j < curAligned.length(); j++) {
21 string curChar = curAligned.substr(j, 1);
22 if(curChar.compare(trump) == 0)
23 columnsToRemove[j] = true;
28 /**************************************************************************************/
29 void FilterSeqsCommand::doSoft() {
30 soft = atoi(globaldata->getSoft().c_str());
31 vector<vector<int> > columnSymbolSums;
32 vector<vector<string> > columnSymbols;
33 for(int i = 0; i < db->get(0).getLength(); i++) {
34 vector<string> symbols;
36 columnSymbols.push_back(symbols);
37 columnSymbolSums.push_back(sums);
40 for(int i = 0; i < db->size(); i++) {
41 Sequence cur = db->get(i);
42 string curAligned = cur.getAligned();
44 for(int j = 0; j < curAligned.length(); j++) {
45 string curChar = curAligned.substr(j, 1);
46 vector<string> curColumnSymbols = columnSymbols[j];
47 bool newSymbol = true;
49 for(int k = 0; k < curColumnSymbols.size(); k++)
50 if(curChar.compare(curColumnSymbols[k]) == 0) {
52 columnSymbolSums[j][k]++;
56 columnSymbols[j].push_back(curChar);
57 columnSymbolSums[j].push_back(1);
63 for(int i = 0; i < columnSymbolSums.size(); i++) {
66 vector<int> curColumnSymbols = columnSymbolSums[i];
68 for(int j = 0; j < curColumnSymbols.size(); j++) {
69 int curSum = curColumnSymbols[j];
70 //cout << columnSymbols[i][j] << ": " << curSum << "\n";
77 if((double)max/(double)totalSum * 100 < soft)
78 columnsToRemove[i] = true;
82 /**************************************************************************************/
83 void FilterSeqsCommand::doFilter() {
84 filter = globaldata->getFilter();
86 openInputFile(filter, filehandle);
90 while(!filehandle.eof()) {
93 columnsToRemove[count] = true;
98 /**************************************************************************************/
99 int FilterSeqsCommand::execute() {
101 globaldata = GlobalData::getInstance();
102 db = globaldata->gSequenceDB;
104 for(int i = 0; i < db->get(0).getLength(); i++)
105 columnsToRemove.push_back(false);
108 if(globaldata->getTrump().compare("") != 0)
110 else if(globaldata->getSoft().compare("") != 0)
113 else if(globaldata->getFilter().compare("") != 0)
116 //for(int i = 0; i < columnsToRemove.size(); i++)
118 // cout << "Remove Column " << i << " = ";
119 // if(columnsToRemove[i])
122 // cout << "false\n";
124 //Creating the new SequenceDB
126 for(int i = 0; i < db->size(); i++) {
127 Sequence curSeq = db->get(i);
128 string curAligned = curSeq.getAligned();
129 string curName = curSeq.getName();
130 string newAligned = "";
131 for(int j = 0; j < curAligned.length(); j++)
132 if(!columnsToRemove[j])
133 newAligned += curAligned.substr(j, 1);
135 Sequence newSeq(curName, newAligned);
140 outfile.open("filtertest.txt");
141 newDB.print(outfile);
146 catch(exception& e) {
147 cout << "Standard Error: " << e.what() << " has occurred in the FilterSeqsCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
151 cout << "An unknown error has occurred in the FilterSeqsCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
155 /**************************************************************************************/