|
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 "../IManager.hpp" 00023 #include "AbstractBlockPruning.hpp" 00024 #include <algorithm> 00025 #include <stdlib.h> 00026 00027 AbstractBlockPruning::AbstractBlockPruning() { 00028 this->bestScore = -INF; 00029 this->grid = NULL; 00030 this->recurrenceType = SMITH_WATERMAN; 00031 this->score_params = NULL; 00032 this->max_i = 0; 00033 this->max_j = 0; 00034 } 00035 00036 AbstractBlockPruning::~AbstractBlockPruning() { 00037 00038 } 00039 00040 void AbstractBlockPruning::updateBestScore(int score) { 00041 if (this->bestScore < score) { 00042 this->bestScore = score; 00043 } 00044 } 00045 00046 const Grid* AbstractBlockPruning::getGrid() const { 00047 return grid; 00048 } 00049 00050 void AbstractBlockPruning::setGrid(const Grid* grid) { 00051 if (this->grid != NULL) { 00052 finalize(); 00053 } 00054 this->grid = grid; 00055 this->bestScore = -INF; 00056 if (this->grid != NULL) { 00057 initialize(); 00058 } 00059 } 00060 00061 void AbstractBlockPruning::setSuperPartition(Partition superPartition) { 00062 this->max_i = superPartition.getI1(); 00063 this->max_j = superPartition.getJ1(); 00064 } 00065 00066 void AbstractBlockPruning::setScoreParams(const score_params_t* score_params) { 00067 this->score_params = score_params; 00068 } 00069 00070 bool AbstractBlockPruning::isBlockPrunable(int bx, int by, int score) { 00071 if (grid == NULL) return false; 00072 int i0; 00073 int j0; 00074 int i1; 00075 int j1; 00076 int adjustment = grid->getBlockAdjustment(bx,by); 00077 grid->getBlockPosition(bx, by, &i0, &j0, &i1, &j1); 00078 if (i0 == -1) { 00079 return true; 00080 } 00081 00082 int distI = max_i - i0; 00083 int distJ = max_j - j0; 00084 00085 int distMin = (distI<distJ)?distI:distJ; 00086 int inc = distMin*score_params->match; 00087 int dec = 0; 00088 00089 //fprintf(stderr, "--isBlockPrunable? (%d,%d) (%d,%d) %d+%d<%d\n", bx, by, i0, j0, score,inc, bestScore); 00090 00091 00092 if (recurrenceType == NEEDLEMAN_WUNSCH) { 00093 int gaps; 00094 00095 gaps = abs(distJ-distI) - std::max(j1-j0, i1-i0); 00096 if (gaps > 0) { 00097 inc -= score_params->gap_open + gaps*score_params->gap_ext; 00098 } 00099 00100 // FIXME - must consider alignment edge instead of recurrenceType 00101 dec -= distMin*score_params->mismatch; 00102 gaps = abs(distJ-distI) + std::max(j1-j0, i1-i0); 00103 dec += score_params->gap_open + gaps*score_params->gap_ext; 00104 } 00105 00106 updateBestScore(score - dec); 00107 00108 int max = score + inc + adjustment; 00109 //fprintf(stderr, "isBlockPrunable(%2d,%2d, [%d/%d]) D:%d +%d-%d - Max: %d\n", bx, by, score, bestScore, distMin, inc, dec, max); 00110 return (max <= bestScore); 00111 } 00112 00113 void AbstractBlockPruning::setRecurrenceType(int recurrenceType) { 00114 this->recurrenceType = recurrenceType; 00115 } 00116 00117 int AbstractBlockPruning::getRecurrenceType() const { 00118 return recurrenceType; 00119 }
1.7.6.1