forked from billiam001/stephenturner.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
explain-flags.html
125 lines (113 loc) · 4.96 KB
/
explain-flags.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!doctype html>
<html>
<script type="text/javascript">
lstFlags = [["read paired", 0x1],
["read mapped in proper pair", 0x2],
["read unmapped", 0x4],
["mate unmapped", 0x8],
["read reverse strand", 0x10],
["mate reverse strand", 0x20],
["first in pair", 0x40],
["second in pair", 0x80],
["not primary alignment", 0x100],
["read fails platform/vendor quality checks", 0x200],
["read is PCR or optical duplicate", 0x400],
["supplementary alignment", 0x800]];
function explainFlags() {
var flagValue = parseInt(document.getElementById('tb').value); //returns 0 or NaN if can't parse
var summary = "";
var badFlags = []; // Stores the flags that don't make sense with unpaired reads
var hexString = ""; // indicator for the user which flags are invalid with unpaired reads
var pairedRead = lstFlags[0][1] & flagValue;
for(var i = 0; i < lstFlags.length; i++) {
var checkbox = document.getElementById('cb' + i)
if(lstFlags[i][1] & flagValue) {
hexString = " (0x" + lstFlags[i][1].toString(16) + ")";
if (!pairedRead && (lstFlags[i][1] & 235)) {
badFlags.push(" 0x" + lstFlags[i][1].toString(16));
hexString += "<b>*</b>";
}
summary += " " + lstFlags[i][0] + hexString + "<br>";
checkbox.checked = true;
} else {
checkbox.checked = false;
}
}
if (badFlags.length > 0){
if (badFlags.length == 2){
badFlags = badFlags.join(" and ");
} else {
badFlags[badFlags.length - 1] = " and" + badFlags[badFlags.length - 1];
}
summary += "<br> <b>*Warning:</b> Flag(s)" + badFlags + " cannot be set when read is not paired";
}
document.getElementById('summary').innerHTML = summary;
}
function checkboxClicked() {
//compute the new flag value
var newFlagValue = 0;
for(var i = 0; i < lstFlags.length; i++) {
var checkBox = document.getElementById('cb' + i);
if(checkBox.checked) {
newFlagValue |= lstFlags[i][1];
}
}
var textbox = document.getElementById('tb');
textbox.value = newFlagValue;
explainFlags();
}
function switchToMate() {
swaps = [[2,3],[4,5],[6,7]]
for( var i = 0 ; i<swaps.length ; i++){
swap1=swaps[i][0]
swap2=swaps[i][1]
val1 = document.getElementById('cb' + swap1).checked;
val2 = document.getElementById('cb' + swap2).checked;
document.getElementById('cb' + swap1).checked=val2
document.getElementById('cb' + swap2).checked=val1
checkboxClicked()
}
}
</script>
<noscript>This page requires JavaScript. Please enable it in your browser settings.</noscript>
<body>
<div class="wrapper">
<h2>Decoding SAM flags</h2>
<section>
<p>This utility makes it easy to identify what are the properties of a read based on its SAM flag value, or conversely, to find what the SAM Flag value would be for a given combination of properties. </p>
<form onSubmit="explainFlags(); return false;" action="">
<p>To decode a given SAM flag value, just enter the number in the field below. The encoded properties will be listed under Summary below, to the right.</p>
SAM Flag:
<input id="tb" type=text size=10 />
<input type=submit value="Explain" />
<br /><br />
<div id="button" align="left">
<button onclick="switchToMate()">Switch to mate</button> <small>Toggle first in pair / second in pair</small>
</div>
<br />
<table style="table-layout: fixed">
<tr>
<td style="width: 50%;">
<strong>Find SAM flag by property:</strong><br />
<p><small>To find out what the SAM flag value would be for a given combination of properties, tick the boxes for those that you'd like to include. The flag value will be shown in the SAM Flag field above.</small></p>
<script type="text/javascript">
for(var i = 0; i < lstFlags.length; i++) {
document.write("<input type=checkbox name=cb" + i + " id='cb" + i + "' onclick='checkboxClicked();'> " +lstFlags[i][0] + "</input><br />");
}
</script>
<br />
</td>
<td style="text-align: left; vertical-align: top; width: 50%">
<strong>Summary:</strong><br />
<div id="summary">
</div>
</td>
</tr>
</table>
<br />
<br />
</form>
</section>
</div>
</body>
</html>