1 /** 2 * UGENE - Integrated Bioinformatics Tools. 3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru> 4 * http://ugene.net 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 #ifndef _SMITHWATERMANALGORITHM_H 23 #define _SMITHWATERMANALGORITHM_H 24 25 #include <QByteArray> 26 #include <QVector> 27 28 #include <U2Algorithm/SmithWatermanSettings.h> 29 30 #include <U2Core/SMatrix.h> 31 32 #include "PairAlignSequences.h" 33 34 namespace U2 { 35 36 class SmithWatermanAlgorithm { 37 public: 38 SmithWatermanAlgorithm(); ~SmithWatermanAlgorithm()39 virtual ~SmithWatermanAlgorithm() { 40 } 41 42 virtual void launch(const SMatrix &m, const QByteArray &_patternSeq, const QByteArray &_searchSeq, int _gapOpen, int _gapExtension, int _minScore, SmithWatermanSettings::SWResultView _resultView); 43 44 QList<PairAlignSequences> getResults(); 45 static void sortByScore(QList<PairAlignSequences> &pairAlignmentStrings); 46 static quint64 estimateNeededRamAmount(const qint32 gapOpen, const qint32 gapExtension, const quint32 minScore, const quint32 maxScore, const QByteArray &patternSeq, const QByteArray &searchSeq, const SmithWatermanSettings::SWResultView resultView); 47 static const char STOP; 48 static const char UP; 49 static const char LEFT; 50 static const char DIAG; 51 52 protected: 53 bool calculateMatrixLength(); 54 bool isValidParams(); 55 void setValues(const SMatrix &_substitutionMatrix, 56 const QByteArray &_patternSeq, 57 const QByteArray &_searchSeq, 58 int _gapOpen, 59 int _gapExtension, 60 int _minScore, 61 SmithWatermanSettings::SWResultView _resultView); 62 63 QList<PairAlignSequences> pairAlignmentStrings; 64 65 SMatrix substitutionMatrix; 66 67 QByteArray patternSeq; 68 QByteArray searchSeq; 69 70 int gapOpen; 71 int gapExtension; 72 int minScore; 73 int matrixLength; 74 SmithWatermanSettings::SWResultView resultView; 75 76 QVector<QVector<char>> directionMatrix; 77 78 struct KeyOfPairAlignSeq { KeyOfPairAlignSeqKeyOfPairAlignSeq79 KeyOfPairAlignSeq(int _score, U2Region const &_intervalSeq1) { 80 setValues(_score, _intervalSeq1); 81 } 82 KeyOfPairAlignSeqKeyOfPairAlignSeq83 KeyOfPairAlignSeq() { 84 score = 0; 85 86 intervalSeq1.startPos = 0; 87 intervalSeq1.length = 0; 88 }; 89 exchangeKeyOfPairAlignSeq90 static void exchange(PairAlignSequences &a, PairAlignSequences &b) { 91 PairAlignSequences bufKey; 92 93 bufKey = a; 94 a = b; 95 b = bufKey; 96 } 97 setValuesKeyOfPairAlignSeq98 void setValues(int _score, U2Region const &_intervalSeq1) { 99 score = _score; 100 intervalSeq1 = _intervalSeq1; 101 } 102 103 int score; 104 U2Region intervalSeq1; 105 }; 106 107 private: 108 QVector<QVector<int>> matrix; 109 QVector<int> EMatrix; 110 QVector<int> FMatrix; 111 112 void calculateMatrixForMultipleAlignmentResult(); 113 void calculateMatrixForAnnotationsResult(); 114 }; 115 116 } // namespace U2 117 118 #endif 119