-
Notifications
You must be signed in to change notification settings - Fork 0
/
complement.html
27 lines (26 loc) · 1.02 KB
/
complement.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE html>
<body>
<form id="seq">
DNA sequence: <input type="text" name="DNAseq" value=""><br>
</form>
<button onclick="complement()">Show complement</button>
<p id="out"></p>
<ul id="seqList">
</ul>
<script type="text/javascript">
COMPLEMENT_BASES={'A':'T','T':'A','G':'C','C':'G'};
function complement() {
var s=document.getElementById("seq").elements[0].value;
var allButFourBaseRE=/[^CGATcgat]/;//.test(s) should return true if s contains a character that is not a C, G, A, T, c, g, a, or t.
if (s.length == 0 || allButFourBaseRE.test(s)) {
alert("This program only works on DNA sequences composed only from the following eight characters: C, G, A, T, c, g, a, or t");
} else {
var reverseSeq=s.split('').reverse().join('');
var complementSeq='';
for (i in reverseSeq){complementSeq=complementSeq+COMPLEMENT_BASES[reverseSeq[i]]};
var list = document.getElementById("seqList");
list.appendChild(document.createElement('li')).appendChild(document.createTextNode(s+' -> '+complementSeq));
};
}
</script>
</body>