Built with blockbuilder.org
Created
April 3, 2016 22:59
-
-
Save Wanagram/0c6020ea8c93c50c7c3657c1598d9a2d to your computer and use it in GitHub Desktop.
fresh block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<script> | |
//The two sequences to compare | |
var sequence1 = "ATTGCTGACTTCA" | |
var sequence2 = "ATGCTACTA" | |
//Creates multi-dimensional array dependent on sequence lengths | |
var arr = new Array(sequence1.length+1) | |
for(i=0;i<sequence1.length+1;i++){ | |
arr[i] = new Array(sequence2.length+1); | |
} | |
//Sets the first row equal to 0 | |
for(i=0;i<arr.length;i++){ | |
arr[i][0] = 0; | |
} | |
//Sets the first column equal to 0 | |
for(i=0;i<sequence2.length+1;i++){ | |
arr[0][i] = 0; | |
} | |
for(i=1;i<arr.length;i++){ | |
var col = i; | |
for(i=1;i<sequence2.length+1;i++){ | |
if(arr[col][i-1]>arr[col][i]){ | |
arr[col][i]=arr[col][i-1]; | |
} | |
if(arr[col-1][i]>arr[col][i]){ | |
arr[col][i]=arr[col-1][i]; | |
} | |
var match = 0; | |
if(sequence1[col-1]==sequence2[i-1]){ | |
match = 1; | |
} | |
if((arr[col-1][i-1]+match)>arr[col][i]){ | |
arr[col][i]=arr[col-1][i-1]+match; | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment