|
MASA-Core
|
00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2010-2015 Edans Sandes 00004 * 00005 * This file is part of MASA-Core. 00006 * 00007 * MASA-Core is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation, either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * MASA-Core is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with MASA-Core. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 ******************************************************************************/ 00021 00022 #include "AbstractAligner.hpp" 00023 00024 #include <stdio.h> 00025 #include <stdlib.h> 00026 00027 #include "../utils/AlignerUtils.hpp" 00028 #include "../pruning/BlockPruningGenericN2.hpp" 00029 00030 /** 00031 * AbstractAligner contructor. 00032 */ 00033 AbstractAligner::AbstractAligner() { 00034 forkWeights = NULL; 00035 forkCount = 0; 00036 grid = NULL; 00037 manager = NULL; 00038 00039 firstColumnTail.h = -INF; 00040 firstColumnTail.f = -INF; 00041 firstRowTail.h = -INF; 00042 firstRowTail.f = -INF; 00043 } 00044 00045 /** 00046 * AbstractAligner destructor. 00047 */ 00048 AbstractAligner::~AbstractAligner() { 00049 if (forkWeights != NULL) { 00050 delete forkWeights; 00051 } 00052 } 00053 00054 00055 /** 00056 * Defines the IManager to be associated with this aligner. 00057 * @param manager the interface to the MASA-Core. 00058 */ 00059 void AbstractAligner::setManager(IManager* manager) { 00060 this->manager = manager; 00061 } 00062 00063 /** 00064 * Defines how many processes may be forked for this aligner and the 00065 * computation weight for each process. 00066 * 00067 * @param forkCount number of processes allowed. 00068 * @param forkWeights vector containing $forkCount$ weights. If NULL, all 00069 * the processes will have the same weight. 00070 */ 00071 void AbstractAligner::setForkCount(const int forkCount, const int* forkWeights) { 00072 this->forkCount = forkCount; 00073 if (this->forkWeights != NULL) { 00074 // forkWeights will be recreated. 00075 delete this->forkWeights; 00076 } 00077 this->forkWeights = new int[forkCount+1]; 00078 if (forkWeights != NULL) { 00079 memcpy(this->forkWeights, forkWeights, sizeof(int)*forkCount); 00080 this->forkWeights[forkCount] = 0; 00081 } else { 00082 // All the weigths are set to the same number, so the processes 00083 // will be equally distributed. 00084 for (int i=0; i<forkCount; i++) { 00085 this->forkWeights[i] = 100; 00086 } 00087 } 00088 } 00089 00090 /** 00091 * Supply the computational power weight defined after the AbstractAligner::setForkCount. 00092 * 00093 * @return the weights for each process. 00094 * @see IAligner::getForkWeights() 00095 */ 00096 const int* AbstractAligner::getForkWeights() { 00097 return forkWeights; 00098 } 00099 00100 /** 00101 * Creates a new grid using the given partition coordinates. If there is 00102 * a previously created grid, it is deleted and overwritten. 00103 * 00104 * @param partition the partition to be split in a grid of blocks. 00105 */ 00106 Grid* AbstractAligner::createGrid(Partition partition) { 00107 if (this->grid != NULL) { 00108 delete this->grid; 00109 } 00110 this->grid = new Grid(partition); 00111 00112 return this->grid; 00113 } 00114 00115 /** 00116 * Returns the grid created by the last call to the AbstractAligner::createGrid 00117 * method. 00118 * 00119 * @return the current grid object. 00120 */ 00121 const Grid* AbstractAligner::getGrid() const { 00122 return grid; 00123 } 00124 00125 /** 00126 * Initializes the pruner object. It must be called after the grid is created 00127 * by the AbstractAligner::createGrid method. 00128 * 00129 * @param blockPruner the pruner object to be initialized. 00130 */ 00131 void AbstractAligner::initializeBlockPruning(AbstractBlockPruning* blockPruner) { 00132 if (this->grid == NULL) { 00133 fprintf(stderr, "The grid is not set. Block pruning cannot be initialized.\n"); 00134 return; 00135 } 00136 if (mustPruneBlocks()) { 00137 blockPruner->setGrid(grid); 00138 blockPruner->setSuperPartition(manager->getSuperPartition()); 00139 blockPruner->setScoreParams(getScoreParameters()); 00140 blockPruner->setRecurrenceType(this->getRecurrenceType()); 00141 } else { 00142 blockPruner->setGrid(NULL); 00143 } 00144 } 00145 00146 /** 00147 * Executes the matching procedure in CPU. This method is a default 00148 * implementation that works in any condition, but a subclass may override it 00149 * in order to create a faster matching procedure for the MASA extension. 00150 * 00151 * @param buffer the vector with the last column data. 00152 * @param base the vector with the special row in the reverse direction. 00153 * @param len Defines that we must match the buffers in the range [0,len). 00154 * @param goalScore the score that will be searched during the matching procedure. 00155 * @return the match result. 00156 * @see IAligner::matchLastColumn for a better explanation of the parameters. 00157 */ 00158 match_result_t AbstractAligner::matchLastColumn(const cell_t* buffer, 00159 const cell_t* base, int len, int goalScore) { 00160 // Executes the matching procedure. 00161 return AlignerUtils::matchColumn(buffer, base, len, goalScore, 00162 getScoreParameters()->gap_open); 00163 } 00164 00165 00166 00167 00168 /* **************** * 00169 * DELEGATE METHODS * 00170 * **************** */ 00171 00172 00173 00174 00175 /** Delegates to IManager::getRecurrenceType() 00176 * @copydoc IManager::getRecurrenceType 00177 * @see IManager::getRecurrenceType() 00178 */ 00179 int AbstractAligner::getRecurrenceType() const { 00180 return this->manager->getRecurrenceType(); 00181 } 00182 00183 /** Delegates to IManager::getSpecialRowInterval() 00184 * @copydoc IManager::getSpecialRowInterval 00185 * @see IManager::getSpecialRowInterval() 00186 */ 00187 int AbstractAligner::getSpecialRowInterval() const { 00188 return this->manager->getSpecialRowInterval(); 00189 } 00190 00191 /** Delegates to IManager::getSpecialColumnInterval() 00192 * @copydoc IManager::getSpecialColumnInterval 00193 * @see IManager::getSpecialColumnInterval() 00194 */ 00195 int AbstractAligner::getSpecialColumnInterval() const { 00196 return this->manager->getSpecialColumnInterval(); 00197 } 00198 00199 /** Delegates to IManager::getSuperPartition() 00200 * @copydoc IManager::getSuperPartition 00201 * @see IManager::getSuperPartition() 00202 */ 00203 Partition AbstractAligner::getSuperPartition() { 00204 return this->manager->getSuperPartition(); 00205 } 00206 00207 /** Delegates to IManager::getFirstColumnInitType() 00208 * @copydoc IManager::getFirstColumnInitType 00209 * @see IManager::getFirstColumnInitType() 00210 */ 00211 int AbstractAligner::getFirstColumnInitType() { 00212 return this->manager->getFirstColumnInitType(); 00213 } 00214 00215 /** Delegates to IManager::getFirstRowInitType() 00216 * @copydoc IManager::getFirstRowInitType 00217 * @see IManager::getFirstRowInitType() 00218 */ 00219 int AbstractAligner::getFirstRowInitType() { 00220 return this->manager->getFirstRowInitType(); 00221 } 00222 00223 /** Delegates to IManager::receiveFirstRow() 00224 * @copydoc IManager::receiveFirstRow 00225 * @see IManager::receiveFirstRow() 00226 */ 00227 void AbstractAligner::receiveFirstRow(cell_t* buffer, int len) { 00228 this->manager->receiveFirstRow(buffer, len); 00229 firstRowTail = buffer[len - 1]; 00230 } 00231 00232 /** Delegates to IManager::receiveFirstColumn() 00233 * @copydoc IManager::receiveFirstColumn 00234 * @see IManager::receiveFirstColumn() 00235 */ 00236 void AbstractAligner::receiveFirstColumn(cell_t* buffer, int len) { 00237 this->manager->receiveFirstColumn(buffer, len); 00238 firstColumnTail = buffer[len - 1]; 00239 } 00240 00241 00242 /** Delegates to IManager::dispatchColumn() 00243 * @copydoc IManager::dispatchColumn 00244 * @see IManager::dispatchColumn() 00245 */ 00246 void AbstractAligner::dispatchColumn(int j, const cell_t* buffer, int len) { 00247 this->manager->dispatchColumn(j, buffer, len); 00248 } 00249 00250 /** Delegates to IManager::dispatchRow() 00251 * @copydoc IManager::dispatchRow 00252 * @see IManager::dispatchRow() 00253 */ 00254 void AbstractAligner::dispatchRow(int i, const cell_t* buffer, int len) { 00255 this->manager->dispatchRow(i, buffer, len); 00256 } 00257 00258 /** Delegates to IManager::dispatchScore() 00259 * @copydoc IManager::dispatchScore 00260 * @see IManager::dispatchScore() 00261 */ 00262 void AbstractAligner::dispatchScore(score_t score, int bx, int by) { 00263 this->manager->dispatchScore(score, bx, by); 00264 } 00265 00266 /** Delegates to IManager::mustContinue() 00267 * @copydoc IManager::mustContinue 00268 * @see IManager::mustContinue() 00269 */ 00270 bool AbstractAligner::mustContinue() { 00271 return this->manager->mustContinue(); 00272 } 00273 00274 /** Delegates to IManager::mustDispatchLastCell() 00275 * @copydoc IManager::mustDispatchLastCell 00276 * @see IManager::mustDispatchLastCell() 00277 */ 00278 bool AbstractAligner::mustDispatchLastCell() { 00279 return this->manager->mustDispatchLastCell(); 00280 } 00281 00282 /** Delegates to IManager::mustDispatchLastRow() 00283 * @copydoc IManager::mustDispatchLastRow 00284 * @see IManager::mustDispatchLastRow() 00285 */ 00286 bool AbstractAligner::mustDispatchLastRow() { 00287 return this->manager->mustDispatchLastRow(); 00288 } 00289 00290 /** Delegates to IManager::mustDispatchLastColumn() 00291 * @copydoc IManager::mustDispatchLastColumn 00292 * @see IManager::mustDispatchLastColumn() 00293 */ 00294 bool AbstractAligner::mustDispatchLastColumn() { 00295 return this->manager->mustDispatchLastColumn(); 00296 } 00297 00298 /** Delegates to IManager::mustDispatchSpecialRows() 00299 * @copydoc IManager::mustDispatchSpecialRows 00300 * @see IManager::mustDispatchSpecialRows() 00301 */ 00302 bool AbstractAligner::mustDispatchSpecialRows() { 00303 return this->manager->mustDispatchSpecialRows(); 00304 } 00305 00306 /** Delegates to IManager::mustDispatchScores() 00307 * @copydoc IManager::mustDispatchScores 00308 * @see IManager::mustDispatchScores() 00309 */ 00310 bool AbstractAligner::mustDispatchScores() { 00311 return this->manager->mustDispatchScores(); 00312 } 00313 00314 /** Delegates to IManager::mustDispatchSpecialColumns() 00315 * @copydoc IManager::mustDispatchSpecialColumns 00316 * @see IManager::mustDispatchSpecialColumns() 00317 */ 00318 bool AbstractAligner::mustDispatchSpecialColumns() { 00319 return this->manager->mustDispatchSpecialColumns(); 00320 } 00321 00322 /** Delegates to IManager::mustPruneBlocks() 00323 * @copydoc IManager::mustPruneBlocks 00324 * @see IManager::mustPruneBlocks() 00325 */ 00326 bool AbstractAligner::mustPruneBlocks() { 00327 return this->manager->mustPruneBlocks(); 00328 } 00329 00330 /** 00331 * @return the last cell read from the first column 00332 */ 00333 cell_t AbstractAligner::getFirstColumnTail() const { 00334 return firstColumnTail; 00335 } 00336 00337 /** 00338 * @return the last cell read from the first row 00339 */ 00340 cell_t AbstractAligner::getFirstRowTail() const { 00341 return firstRowTail; 00342 } 00343 00344
1.7.6.1