MSA/MSA.cpp
//two sequences alignment, and score it.
//something like Needleman-Wunsch alg.

two sequences alignment, and score it.
something like Needleman-Wunsch alg.
two sequences alignment and score it . something like Needleman - Wunsch alg .
double MSA::ScoreAlignAlignments(unsigned int firstSet, unsigned int secondSet)
{
    int currentSetOneLength=0;
    int currentSetTwoLength=0;
    for (int i = 0; i < number_of_Sequences; ++i) {
        if (Aligning_Sequence[i].label == firstSet){
            currentSetOneLength = Aligning_Sequence[i].sequence.size();
            break;
        }
    }
    for (int i = 0; i < number_of_Sequences; ++i) {
        if (Aligning_Sequence[i].label == secondSet){
            currentSetTwoLength = Aligning_Sequence[i].sequence.size();
            break;
        }
    }
    vector<vector<double> > scoreMatrix;
    scoreMatrix.resize(currentSetOneLength + 1);
    for (int i = 0; i < currentSetOneLength + 1; ++i) {
        scoreMatrix[i].resize(currentSetTwoLength + 1);
    }
    scoreMatrix[0][0] = 0;
    for (int i = 1; i <= currentSetOneLength; ++i) {
        scoreMatrix[i][0] = scoreMatrix[i - 1][0] + AlignColumnToSpace(firstSet, i);
    }
    for (int j = 1; j <= currentSetTwoLength; ++j) {
        scoreMatrix[0][j] = scoreMatrix[0][j - 1] + AlignColumnToSpace(secondSet, j);
    }
    double matchScore = 0;
    double delA = 0;
    double insB = 0;
    for (int i = 1; i <= currentSetOneLength; ++i) {
        for (int j = 1; j <= currentSetTwoLength; ++j)
        {
            matchScore = scoreMatrix[i - 1][j - 1] + AlignColumnToColumn(firstSet, i, secondSet, j);
            delA = scoreMatrix[i - 1][j] + AlignColumnToSpace(firstSet, i);
            insB = scoreMatrix[i][j - 1] + AlignColumnToSpace(secondSet, j);
            scoreMatrix[i][j] = MaxofThree(matchScore, delA, insB);
        }
    }
    double temp = scoreMatrix[currentSetOneLength][currentSetTwoLength];
    scoreMatrix.clear();
    return temp;
}
double MSA :: ScoreAlignAlignments ( unsigned int firstSet , unsigned int secondSet ) { int currentSetOneLength = 0 ; int currentSetTwoLength = 0 ; for ( int i = 0 ; i < number_of_Sequences ; ++ i ) { if ( Aligning_Sequence [ i ] . label == firstSet ) { currentSetOneLength = Aligning_Sequence [ i ] . sequence . size ( ) ; break ; } } for ( int i = 0 ; i < number_of_Sequences ; ++ i ) { if ( Aligning_Sequence [ i ] . label == secondSet ) { currentSetTwoLength = Aligning_Sequence [ i ] . sequence . size ( ) ; break ; } } vector < vector < double > > scoreMatrix ; scoreMatrix . resize ( currentSetOneLength + 1 ) ; for ( int i = 0 ; i < currentSetOneLength + 1 ; ++ i ) { scoreMatrix [ i ] . resize ( currentSetTwoLength + 1 ) ; } scoreMatrix [ 0 ] [ 0 ] = 0 ; for ( int i = 1 ; i <= currentSetOneLength ; ++ i ) { scoreMatrix [ i ] [ 0 ] = scoreMatrix [ i - 1 ] [ 0 ] + AlignColumnToSpace ( firstSet , i ) ; } for ( int j = 1 ; j <= currentSetTwoLength ; ++ j ) { scoreMatrix [ 0 ] [ j ] = scoreMatrix [ 0 ] [ j - 1 ] + AlignColumnToSpace ( secondSet , j ) ; } double matchScore = 0 ; double delA = 0 ; double insB = 0 ; for ( int i = 1 ; i <= currentSetOneLength ; ++ i ) { for ( int j = 1 ; j <= currentSetTwoLength ; ++ j ) { matchScore = scoreMatrix [ i - 1 ] [ j - 1 ] + AlignColumnToColumn ( firstSet , i , secondSet , j ) ; delA = scoreMatrix [ i - 1 ] [ j ] + AlignColumnToSpace ( firstSet , i ) ; insB = scoreMatrix [ i ] [ j - 1 ] + AlignColumnToSpace ( secondSet , j ) ; scoreMatrix [ i ] [ j ] = MaxofThree ( matchScore , delA , insB ) ; } } double temp = scoreMatrix [ currentSetOneLength ] [ currentSetTwoLength ] ; scoreMatrix . clear ( ) ; return temp ; }
two sequences alignment, and score it.
two sequences alignment and score it .
//initialize score Matrix
 //A is the vertical axis, B is the horizontal axis
