00001 #ifndef FILTER_CPP 00002 #define FILTER_CPP 00003 00004 //-------------------------------------------------------------------- 00005 // 00006 // This file is part of PEACE. 00007 // 00008 // PEACE is free software: you can redistribute it and/or modify it 00009 // under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation, either version 3 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // PEACE is distributed in the hope that it will be useful, but 00014 // WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with PEACE. If not, see <http://www.gnu.org/licenses/>. 00020 // 00021 // Miami University makes no representations or warranties about the 00022 // suitability of the software, either express or implied, including 00023 // but not limited to the implied warranties of merchantability, 00024 // fitness for a particular purpose, or non-infringement. Miami 00025 // University shall not be liable for any damages suffered by licensee 00026 // as a result of using, result of using, modifying or distributing 00027 // this software or its derivatives. 00028 // 00029 // By using or copying this Software, Licensee agrees to abide by the 00030 // intellectual property laws, and all other applicable laws of the 00031 // U.S., and the terms of GNU General Public License (version 3). 00032 // 00033 // Authors: Dhananjai M. Rao raodm@muohio.edu 00034 // 00035 //--------------------------------------------------------------------- 00036 00037 #include "Filter.h" 00038 #include "Utilities.h" 00039 #include "ClusterMaker.h" 00040 00041 Filter::Filter(const std::string& name, ClusterMaker* clsMaker) 00042 : filterName(name), clusterMaker(clsMaker) { 00043 runCount = 0; 00044 filterCount = 0; 00045 // Nothing else to be done for now. 00046 } 00047 00048 Filter::~Filter() { 00049 // Empty constructor begets an empty destructor 00050 } 00051 00052 int 00053 Filter::applyFilter(const int estIndex) { 00054 int clusterIndex; 00055 if ((clusterIndex = runFilter(estIndex)) != -1) { 00056 // This EST was filtered out. 00057 filterCount++; 00058 // Track the filtered EST information for distribution to 00059 // other processes later on. 00060 filteredESTList[clusterIndex].push_back(estIndex); 00061 // Add this EST to the clsuter 00062 clusterMaker->addEST(clusterIndex, estIndex); 00063 } 00064 // Track number of times this filter was run. 00065 runCount++; 00066 // Return cluster index or -1 if this EST passed this filter test. 00067 return clusterIndex; 00068 } 00069 00070 void 00071 Filter::addFilterData(std::vector<int>& superList) const { 00072 for(FilteredESTList::const_iterator curr = filteredESTList.begin(); 00073 (curr != filteredESTList.end()); curr++) { 00074 // Add cluster index to super list first. 00075 superList.push_back(curr->first); 00076 // Now add information about the ests 00077 const std::vector<int>& estList = curr->second; 00078 // Add number of ests filtered 00079 superList.push_back(estList.size()); 00080 // Add the ESTs themselves. 00081 superList.reserve(estList.size()); 00082 superList.insert(superList.end(), estList.begin(), estList.end()); 00083 } 00084 } 00085 00086 void 00087 Filter::processFilterData(const std::vector<int>& superList, 00088 ClusterMaker *clusterMaker) { 00089 // Process sets of entries until we find a end-of-list marker with 00090 // the entry "-1, 0". 00091 int currIndex = 0; 00092 while (superList[currIndex] != -1) { 00093 // First entry is the cluster to which ESTs are to be added. 00094 const int clusterID = superList[currIndex]; 00095 // The second entry is number of ESTs in the list. 00096 const int estCount = superList[currIndex + 1]; 00097 // Add all ESTs to the dummy cluster. 00098 for(int i = 0; (i < estCount); i++) { 00099 clusterMaker->addEST(clusterID, superList[currIndex + i + 2]); 00100 } 00101 // We have processed one batch of filter data. Onto the next. 00102 currIndex += (estCount + 2); 00103 } 00104 } 00105 00106 void 00107 Filter::printStats(std::ostream& os) const { 00108 os << "Statistics from " << getName() << " filter:\n" 00109 << "\tNumber of calls : " << runCount << "\n" 00110 << "\tNumber of ESTs filtered : " << filterCount << std::endl; 00111 } 00112 00113 #endif
1.6.1