Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
114 views
in Technique[技术] by (71.8m points)

javascript - Finding Subsequences for a Dot-plot matrix

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...