diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d98ff95 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,44 @@ +{ + "files.associations": { + "ostream": "cpp", + "cctype": "cpp", + "cmath": "cpp", + "concepts": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "map": "cpp", + "memory": "cpp", + "new": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "utility": "cpp", + "xfacet": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocinfo": "cpp", + "xlocnum": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" + } +} \ No newline at end of file diff --git a/NormalScore.txt b/NormalScore.txt new file mode 100644 index 0000000..771bc82 --- /dev/null +++ b/NormalScore.txt @@ -0,0 +1,5 @@ +# A C G T +T -1 -1 -1 1 +G -1 -1 1 +C -1 1 +A 1 diff --git a/PAM250.txt b/PAM250.txt new file mode 100644 index 0000000..9340309 --- /dev/null +++ b/PAM250.txt @@ -0,0 +1,21 @@ +# A R N D C Q E G H I L K M F P S T W Y V +V 0 -2 -2 -2 -2 -2 -2 -1 -2 4 2 -2 2 -1 -1 -1 0 -5 -2 4 +Y -3 -4 -2 -4 0 -4 -4 -5 0 -1 -1 -4 -2 7 -5 -3 -3 0 10 +W -6 2 -4 -7 -8 -5 -7 -7 -3 -5 -2 -3 -4 0 -6 -2 -5 17 +T 1 -1 0 0 -2 -1 0 0 -1 0 -2 0 -1 -2 0 1 3 +S 1 0 1 0 0 -1 0 1 -1 -1 -3 0 -2 -3 1 3 +P 1 0 -1 -1 -3 0 -1 -1 0 -2 -3 -1 -2 -5 6 +F -4 -4 -4 -6 -4 -5 -5 -5 -2 1 2 -5 0 9 +M -1 0 -2 -3 -5 -1 -2 -3 -2 2 4 0 6 +K -1 3 1 0 -5 1 0 -2 0 -2 -3 5 +L -2 -3 -3 -4 -6 -2 -3 -4 -2 2 6 +I -1 -2 -2 -2 -2 -2 -2 -3 -2 5 +H -1 2 2 1 -3 3 1 -2 6 +G 1 -3 0 1 -3 -1 0 5 +E 0 -1 1 3 -5 2 4 +Q 0 1 1 2 -5 4 +C -2 -4 -4 -5 4 +D 0 -1 2 4 +N 0 0 2 +R 2 6 +A 2 \ No newline at end of file diff --git a/Sequence.txt b/Sequence.txt new file mode 100644 index 0000000..e69de29 diff --git a/Wunsch.cpp b/Wunsch.cpp new file mode 100644 index 0000000..810df8d --- /dev/null +++ b/Wunsch.cpp @@ -0,0 +1,218 @@ +// CPP program to implement sequence alignment +// problem. +// #include +#include +#include +#include +#include +using namespace std; + +// int match = 1; +// int gap = -1; +std::map> scoring; +char chars[20]; + + + + + +void loadscorematrix(string name){ + ifstream inp(name); + string line; + if (inp.is_open()){ + getline(inp,line); + // cout << line; + // cout << line.find(' ') << endl; + line.erase(0,line.find(' ')+1); + // cout << "Hey"; + int i = 0; + while (line.size() > 0){ + char c = line[0]; + chars[i] = c; + // cout << c << endl; + if (line.size() > 2){ + // cout << line << endl; + line.erase(0,line.find(' ')+1); + } + else{ + // cout << line.find(' ') << endl; + line.erase(0,line.size()+1); + } + i++; + } + i = 0; + int j; + while (getline(inp,line)){ + line.erase(0,2); + j = 0; + while(line.size() > 2){ + // cout << chars[20-i-1] << " " << chars[j] << endl; + int score = stoi(line.substr(0,line.find(' ')+1)); + scoring[chars[20-i-1]][chars[j]] = score; + scoring[chars[j]][chars[20-i-1]] = score; + // cout << score << endl; + j++; + line.erase(0,line.find(' ')+1); + } + // cout << chars[20-i-1] << "HERE" << endl; + scoring[chars[20-i-1]][chars[j]] = stoi(line); + // cout << stoi(line) << endl; + i++; + } + }else{ + cout << "File not found" << endl; + } +} + +void writeToFile(string str, string name){ + string res = "result/" + name + ".txt"; + + +} + + + +void needleman(string seq1, string seq2,string name, string name2, int gap){ + int x,y; + x = seq1.size(); + y = seq2.size(); + // printf("halo"); + // cout << x << " " << y ; + // int **matrix = new int[x+1][y+1]; + // int matrix[x+1][y+1]; + cout << x << " " << y; + int **matrix = new int*[x+1]; + for (int i = 0; i <= x; i++){ + matrix[i] = new int[y+1]; + // cout << i << endl; + } + for (int i=0; i<=x;i++){ + for (int j = 0; j<=y;j++){ + matrix[i][j] = 0; + // cout << "Tes"; + } + } + + for (int i=0; i <= x; i++){ + matrix[i][0] = i * gap; + } + for (int i=0; i <= y; i++){ + matrix[0][i] = i * gap; + } + + for (int i=1; i<= x; i++){ + for (int j =1 ; j <= y; j++){ + // if (seq1[i-1] == seq2[j-1]){ + // matrix[i][j] = scoring[seq1[i-1]][seq2[j-1]] + matrix[i-1][j-1]; + // } + // else{ + // cout << "Tes" << endl; + int top, left, diag, little; + top = matrix[i-1][j] + gap; + left = matrix[i][j-1] + gap; + diag = matrix[i-1][j-1] + scoring[seq1[i-1]][seq2[j-1]]; + if (top < left){ + if (left < diag){ + little = diag; + } + else{ + little = left; + } + }else{ + if (top < diag){ + little = diag; + } + else{ + little = top; + } + } + matrix[i][j] = little; + // } + } + } + + string xend = "",yend = ""; + int i = x; + int j = y; + + while ( i != 0 || j != 0){ + if (i == 0 && j != 0){ + xend = "_" + xend; + yend = seq2[j-1] + yend; + j--; + }else if (j == 0 && i != 0){ + yend = "_" + yend; + xend = seq1[i-1] + xend; + i--; + } + else if (j != 0 && i != 0){ + if (matrix[i-1][j] + gap == matrix[i][j]){ + xend = seq1[i-1] + xend; + yend = "_" + yend; + i--; + } + else if (matrix[i][j-1] + gap == matrix[i][j]){ + xend = "_" + xend; + yend = seq2[j-1] + yend; + j--; + } + else{ + xend = seq1[i-1] + xend; + yend = seq2[j-1] + yend; + i--; + j--; + } + } + } + cout << "Best Score : " << matrix[x][y] << endl; + cout << xend << endl; + cout << yend << endl; + // for (int i =0; i <= x; i++){ + // for (int j = 0 ; j <= y ; j ++){ + // cout << matrix[i][j] << " "; + // } + // cout << endl; + // } + +} + +void withNamaFile(string nama1, string nama2, int gap){ + string str1="",str2=""; + ifstream inp(nama1); + string line; + if (inp.is_open()){ + getline(inp,line); + cout << "First sequence : " << line << endl; + while (getline(inp,line)){ + str1 = str1+line; + } + } + else{ + cout << "File 1 not found" << endl; + } + ifstream inp2(nama2); + if (inp2.is_open()){ + getline(inp2,line); + cout << "Second sequence : " << line << endl; + while(getline(inp2,line)){ + // cout << line; + str2 = str2 + line; + } + } + // cout << str1 << endl; + // cout << str2 << endl; + return needleman(str1,str2,nama1,nama2,gap); +} + + + +int main(int argc, char* argv[]){ + if (argc < 2) + cout << "Maaf kurang argumen, berikan file yang ingin dialign, lalu scoring matrix diakhir, lalu nilai jika terjadi gap" << endl; + else{ + loadscorematrix(argv[argc-2]); + int gap = stoi(argv[argc-1]); + // needleman(argv[1],argv[2],-1); + withNamaFile(argv[1],argv[2],-1); + } +} \ No newline at end of file diff --git a/data/nucleotide/MT019529.1.fasta b/data/nucleotide/MT019529.1.fasta index 5a5f5b8..f605ed4 100644 --- a/data/nucleotide/MT019529.1.fasta +++ b/data/nucleotide/MT019529.1.fasta @@ -426,4 +426,4 @@ GTGCAGAATGAATTCTCGTAACTACATAGCACAAGTAGATGTAGTTAACTTTAATCTCACATAGCAATCT TTAATCAGTGTGTAACATTAGGGAGGACTTGAAAGAGCCACCACATTTTCACCGAGGCCACGCGGAGTAC GATCGAGTGTACAGTGAACAATGCTAGGGAGAGCTGCCTATATGGAAGAGCCCTAATGTGTAAAATTAAT TTTAGTAGTGCTATCCCCATGTGATTTTAATAGCTTCTTAGGAGAATGACAAAAAAAAAAAAAAAAAAAA -AAAAAAAAA +AAAAAAAAA \ No newline at end of file diff --git a/data/nucleotide/MT044258.1.fasta b/data/nucleotide/MT044258.1.fasta index 53bfd35..67fd615 100644 --- a/data/nucleotide/MT044258.1.fasta +++ b/data/nucleotide/MT044258.1.fasta @@ -425,4 +425,4 @@ ATATAAACGTTTTCGCTTTTCCGTTTACGATATATAGTCTACTCTTGTGCAGAATGAATTCTCGTAACTA CATAGCACAAGTAGATGTAGTTAACTTTAATCTCACATAGCAATCTTTAATCAGTGTGTAACATTAGGGA GGACTTGAAAGAGCCACCACATTTTCACCGAGGCCACGCGGAGTACGATCGAGTGTACAGTGAACAATGC TAGGGAGAGCTGCCTATATGGAAGAGCCCTAATGTGTAAAATTAATTTTAGTAGTGCTATCCCCATGTGA -TTTTAATAGCTTCTTAGGAGAATGACAAAAAAAAAAAA +TTTTAATAGCTTCTTAGGAGAATGACAAAAAAAAAAAA \ No newline at end of file diff --git a/data/protein/AGP04929.1.fasta b/data/protein/AGP04929.1.fasta index 9d94e62..c5e0786 100644 --- a/data/protein/AGP04929.1.fasta +++ b/data/protein/AGP04929.1.fasta @@ -18,4 +18,4 @@ ILARLDTVEQEAQIDRLINGRLTSLNAFVAQQLVRTEAAARSAQLAQDKVNECVKSQSKRNGFCGTGTHI VSFAINAPNGLYFFHVGYQPTSHVNATAAYGLCNTENPQKCIAPIDGYFVLNQTTSTVADSDQQWYYTGS SFFHPEPITEANSKYVSMDVKFENLTNRLPPPLLSNSTDLDFKEELEEFFKNVSSQGPNFQEISKINTTL LNLNTELMVLSEVVKQLNESYIDLKELGNYTFYQKWPWYIWLGFIAGLVALALCVFFILCCTGCGTSCLG -KLKCNRCCDSYDEYEVEKIHIH +KLKCNRCCDSYDEYEVEKIHIH \ No newline at end of file diff --git a/data/protein/AYN64561.1.fasta b/data/protein/AYN64561.1.fasta index 4a6f3ed..a3a87b9 100644 --- a/data/protein/AYN64561.1.fasta +++ b/data/protein/AYN64561.1.fasta @@ -18,4 +18,4 @@ FGAISSSLQEILSRLDNLEAQVQIDRLINGRLTALNAYVSQQLSDITLIKAGASRAIEKVNECVKSQSPR INFCGNGNHILSLVQNAPYGLLFIHFSYKPTSFKTVLVSPGLCLSGDRGIAPKQGYFIKQNDSWMFTGSS YYYPEPISDKNVVFMNSCSVNFTKAPFIYLNNSIPNLSDFEAEFSLWFKNHTSIAPNLTFNSHINATFLD LYYEMNVIQESIKSLNSSFINLKEIGTYEMYVKWPWYIWLLIVILFIIFLMILFFICCCTGCGSACFSKC -HNCCDEYGGHNDFVIKASHDD +HNCCDEYGGHNDFVIKASHDD \ No newline at end of file diff --git a/tes.py b/tes.py new file mode 100644 index 0000000..8141159 --- /dev/null +++ b/tes.py @@ -0,0 +1,121 @@ +SEQUENCE_1 = 'AGGGCT' #Sequence 1 (Side Sequence) +SEQUENCE_2 = 'AGGCAT' #Sequence 2 (Top Sequence) +MATRIX_ROW_N = len(SEQUENCE_1)+1 #Initiation Matrix Size (Rows) +MATRIX_COLUMN_N = len(SEQUENCE_2)+1 #Initiation Matrix Size (Columns) +MATCH_SCORE = 5 #Match Score +MISMATCH_SCORE = -3 #Mismatch Score +GAP_SCORE = -5 #Gap Points +GAP_CHARACTER = '-'#Character to Represent Gaps in Final Alignemnts +ALN_PATHWAYS = [] #Initiating List of Discovered aln Pathways +MATRIX = [[[[None] for i in range(2)] for i in range(MATRIX_COLUMN_N)] for i in range(MATRIX_ROW_N)] # Initiating Score Matrix + +def print_aln_details(aln): # Function to print steps of particular aln + print('\n>>>>>>>>>>>>>>>> Aln #:'+str(aln[4])+' <<<<<<<<<<<<<<<<\n\n------------------Steps------------------\n') + for elem in aln[3]: + print('Step: '+str(elem[0])+' -> Score = ' + str(elem[1]) + ' -> Dir: ' + ('\u2190' if elem[2]==1 else ('\u2196' if elem[2]==2 else ('\u2191' if elem[2]==3 else 'Error')))) + print('\n-------------Final aln-------------\n') + print(aln[1]+'\n'+aln[0]) + return + +def print_all(ALIGNMENTS): #Function to print everything + print('Total Alignments: ' + str(len(ALIGNMENTS))) + print('Overall Score: '+str(ALIGNMENTS[0][3][0][1])+'\n') + for elem in ALIGNMENTS: + print_aln_details(elem) + return +def print_alns_only(ALIGNMENTS): #Function to print only ALIGNMENTS + print('Total Alignments: ' + str(len(ALIGNMENTS))) + print('Overall Score: '+str(ALIGNMENTS[0][3][0][1])+'\n') + for elem in ALIGNMENTS: + print(elem[0]+'\n'+elem[1]+'\n') + return +def find_each_path(c_i,c_j,path=''): #Nested function to discover new aln pathways + global ALN_PATHWAYS + i = c_i + j = c_j + if i == 0 and j==0: + ALN_PATHWAYS.append(path) + return 2 + dir_t = len(MATRIX[i][j][1]) + while dir_t<=1: + n_dir = MATRIX[i][j][1][0] if (i != 0 and j != 0) else (1 if i == 0 else (3 if j==0 else 0)) + path = path + str(n_dir) + if n_dir == 1: + j=j-1 + elif n_dir == 2: + i=i-1 + j=j-1 + elif n_dir == 3: + i=i-1 + dir_t = len(MATRIX[i][j][1]) + if i == 0 and j==0: + ALN_PATHWAYS.append(path) + return 3 + if dir_t>1: + for dir_c in range(dir_t): + n_dir = MATRIX[i][j][1][dir_c] if (i != 0 and j != 0) else (1 if i == 0 else (3 if j==0 else 0)) + tmp_path = path + str(n_dir) + if n_dir == 1: + n_i = i + n_j=j-1 + elif n_dir == 2: + n_i=i-1 + n_j=j-1 + elif n_dir == 3: + n_i=i-1 + n_j = j + find_each_path(n_i,n_j,tmp_path) + return len(ALN_PATHWAYS) + +#Main Code +#Matrix Evaulation [start] +for i in range(MATRIX_ROW_N): + MATRIX[i][0] = [GAP_SCORE*i,[]] +for j in range(MATRIX_COLUMN_N): + MATRIX[0][j] = [GAP_SCORE*j,[]] +for i in range(1,MATRIX_ROW_N): + for j in range(1,MATRIX_COLUMN_N): + score = MATCH_SCORE if (SEQUENCE_1[i-1] == SEQUENCE_2[j-1]) else MISMATCH_SCORE + h_val = MATRIX[i][j-1][0] + GAP_SCORE + d_val = MATRIX[i-1][j-1][0] + score + v_val = MATRIX[i-1][j][0] + GAP_SCORE + o_val = [h_val, d_val, v_val] + MATRIX[i][j] = [max(o_val), [i+1 for i,v in enumerate(o_val) if v==max(o_val)]] # h = 1, d = 2, v = 3 +#Matrix Evaulation [end] +OVERALL_SCORE = MATRIX[i][j][0] +score = OVERALL_SCORE +l_i = i +l_j = j +ALIGNMENTS = [] +tot_aln = find_each_path(i,j) +aln_count = 0 +#Compiling alignments based on discovered matrix pathways +for elem in ALN_PATHWAYS: + i = l_i-1 + j = l_j-1 + side_aln = '' + top_aln = '' + step = 0 + aln_info = [] + for n_dir_c in range(len(elem)): + n_dir = elem[n_dir_c] + score = MATRIX[i+1][j+1][0] + step = step + 1 + aln_info.append([step,score,n_dir]) + if n_dir == '2': + side_aln = side_aln + SEQUENCE_1[i] + top_aln = top_aln + SEQUENCE_2[j] + i=i-1 + j=j-1 + elif n_dir == '1': + side_aln = side_aln + GAP_CHARACTER + top_aln = top_aln + SEQUENCE_2[j] + j=j-1 + elif n_dir == '3': + side_aln = side_aln + SEQUENCE_1[i] + top_aln = top_aln + GAP_CHARACTER + i=i-1 + aln_count = aln_count + 1 + ALIGNMENTS.append([top_aln[::-1],side_aln[::-1],elem,aln_info,aln_count]) + +print_alns_only(ALIGNMENTS) \ No newline at end of file diff --git a/w.exe b/w.exe new file mode 100644 index 0000000..e48b096 Binary files /dev/null and b/w.exe differ