I have been trying to code the Dot plot matrix in javascript. I want to find the common subsequences given 2 DNA sequences. Here is my attempt
The idea i thought of was given a dotplot matrix from the first row i try to find the matches(over here the match is denoted as 1). When i find i will check the diagonally next element in the matrix whether its 1 or not. If it is i keep on moving like that unless i get a 0 or null. I want to save those locations that have 1 in an array. Those locations i can use to find the common subsequences.
//Array to store location from the matrix
var r=[];
// Creating a function to find subsequence given length of matrix as parameter
function subseq(k){
for(var ii=0;ii<k;i++){
for(var jj=0;jj<k;jj++){
if(matt[ii][jj]==1){
r=ii;
// Using a while loop to move diagonally
while(matt[ii+1][jj+1]==1 && matt[ii+1][jj+1]!= null && matt[ii+1][jj+1]!= 0)
{
r=ii+1;
}
}
}
console.log(r);
}
}
The issue i face is when i create a dot-plot for 2 same sequences it goes out of bounds.
seq="ACCTGACCTCACCTGAGTTA"
Here is my dot-plot matrix code
function point(x,y){
if(x==y){
return 1
}
else{
return 0
}
}
var matt=[];
function dot(S1,S2){
if(S1.length != S2.length){
return null
}
let len=S1.length-1;
for (var i = 0; i < len+1; i++) {
matt[i] = new Array(len);
}
console.log(matt);
for(var m=0;m<len+1;m++){
for(var n=0;n<len+1;n++){
matt[m][n]=point(S1[n],S2[m]);
}
}
}
question from:
https://stackoverflow.com/questions/65901671/finding-subsequences-for-a-dot-plot-matrix 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…