0

Hello I have been attempting to add a scoring scheme which is 11 for internal gaps, 8 for terminal gaps on the 5 prime end, 7 for gaps on the 3' end, 4 for mismatches, 0 for matches. Currently the code only accounts for internal gap (= 11), mismatches(= 4) and matches (=0) but not for terminal gaps. Im fairly new to coding so I apologise in advance if my code is messy, any guidance is appreciated. I should be getting a score of 275. The two sequences I used are included in the code.

#include <iostream>

#include <fstream>


#include <bits/stdc++.h> 

using namespace std; 

void getscore(string x, string y, int pxy, int pgap) 
{ 
    int i, j; 

    int m = x.length(); 
    int n = y.length(); 


    int dp[n+m+1][n+m+1] = {0}; 


    for (i = 0; i <= (n+m); i++) 
    { 
        dp[i][0] = i * pgap; 
        dp[0][i] = i * pgap; 
    }    


    for (i = 1; i <= m; i++) 
    { 
        for (j = 1; j <= n; j++) 
        { 
            if (x[i - 1] == y[j - 1]) 
            { 
                dp[i][j] = dp[i - 1][j - 1]; 
            } 
            else
            { 
                dp[i][j] = min({dp[i - 1][j - 1] + pxy , 
                                dp[i - 1][j] + pgap , 
                                dp[i][j - 1] + pgap }); 
            } 
        } 
    } 


    int l = n + m; 

    i = m; j = n; 

    int xpos = l; 
    int ypos = l; 


    int xans[l+1], yans[l+1]; 

    while ( !(i == 0 || j == 0)) 
    { 
        if (x[i - 1] == y[j - 1]) 
        { 
            xans[xpos--] = (int)x[i - 1]; 
            yans[ypos--] = (int)y[j - 1]; 
            i--; j--; 
        } 
        else if (dp[i - 1][j - 1] + pxy == dp[i][j]) 
        { 
            xans[xpos--] = (int)x[i - 1]; 
            yans[ypos--] = (int)y[j - 1]; 
            i--; j--; 
        } 
        else if (dp[i - 1][j] + pgap == dp[i][j]) 
        { 
            xans[xpos--] = (int)x[i - 1]; 
            yans[ypos--] = (int)'_'; 
            i--; 
        } 
        else if (dp[i][j - 1] + pgap == dp[i][j]) 
        { 
            xans[xpos--] = (int)'_'; 
            yans[ypos--] = (int)y[j - 1]; 
            j--; 
        } 
    } 
    while (xpos > 0) 
    { 
        if (i > 0) xans[xpos--] = (int)x[--i]; 
        else xans[xpos--] = (int)'_'; 
    } 
    while (ypos > 0) 
    { 
        if (j > 0) yans[ypos--] = (int)y[--j]; 
        else yans[ypos--] = (int)'_'; 
    } 


    int id = 1; 
    for (i = l; i >= 1; i--) 
    { 
        if ((char)yans[i] == '_' && (char)xans[i] == '_') 
        { 
            id = i + 1; 
            break; 
        } 
    } 

    // Printing the final answer 
    cout << "Optimal score = "; 
    cout << dp[m][n] << "\n"; 
    cout << "Optimal alignment :\n"; 
    for (i = id; i <= l; i++) 
    { 
        cout<<(char)xans[i]; 
    } 
    cout << "\n"; 
    for (i = id; i <= l; i++) 
    { 
        cout << (char)yans[i]; 
    } 
    return; 
} 



int main(){ 

    string geneA = "TCTGGTGTCCTAGGCGTAGAGGAACCACACCAATCCATCCCGAACTCTGGTGGTTAAACTCTACTGCGGTGACGATACT "; 
    string geneB = "TGGTGCGGTCATACCAGCGCTAATGCACCGGATCCCATCAGAACTCCGCAGTTAAGCGCGCTTGGGCCAGAACAGTACTGGGATGGGTGTCC "; 


    int misMatchPenalty = 4; 
    int gapPenalty = 11;
    int tPenalty=7;
    int fPenalty=8;


    getscore(geneA, geneB, 
        misMatchPenalty, gapPenalty); 
    return 0;
}
Nata
  • 19
  • 2
  • Warning: Variable size arrays are not part of the standard. [Here's how to create variable size arrays](https://stackoverflow.com/q/57367473/10957435). Also, [don't use bits/stdc++.h](https://stackoverflow.com/q/31816095/10957435). –  Feb 12 '20 at 06:04
  • Thank you for your comment I will keep that in mind for future, I just need the code to produce the output that I require for now and am wondering how to include that – Nata Feb 12 '20 at 06:34
  • Fix the code to be standard conforming first; add functionality after. – L. F. Feb 12 '20 at 09:24
  • I am waiting on if I can get someone to answer on how to fix it functionality and then make all the improvements mentioned here in one go. – Nata Feb 12 '20 at 17:07

0 Answers0