index.html 49.2 KB
Newer Older
jhoogenboom's avatar
jhoogenboom committed
1 2
<!DOCTYPE html>
<html>
jhoogenboom's avatar
jhoogenboom committed
3
<head>
4
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
5
    <meta name="viewport" content="width=device-width, initial-scale=1">
jhoogenboom's avatar
jhoogenboom committed
6
    <meta charset="UTF-8">
7
    <title>Sample Visualisation - FDSTools</title>
jhoogenboom's avatar
jhoogenboom committed
8 9 10 11 12
    <!-- BEGIN_LIBRARIES -->
    <script src="http://vega.github.io/vega-editor/vendor/d3.min.js"></script>
    <script src="http://vega.github.io/vega/vega.min.js"></script>
    <!-- END_LIBRARIES -->
    <style>
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
    input {
        font-family: inherit;
        font-size: 1em;
    }
    .icon {
        padding: 1em;
        margin-right: .25em;
        background-size: contain;
        background-position: center;
        background-repeat: no-repeat;
    }
    .icon.warning {
        background-image: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjYwIiBoZWlnaHQ9IjI2MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnI\
        j48cGF0aCBmaWxsPSIjZmZjYzAwIiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNyIgc3Ryb2tlLW1pdGVybGltaXQ9IjQiIGQ9Im0xMy42ODQyNDIsMjEwLjk2MDk\
        wN2MtMS42MzE4MzIsMy4xNDE5ODMgLTMuNTU1MTQzLDYuMDc5NTU5IC0zLjU1NTMyMyw5LjUyNzg2M2wwLjAxNjEyMSwxLjQ0MTIwOGMwLDcuNDQyNDkgNS44MzA5OCwxMS45N\
        DE3MjcgMTIuNTM0NzI3LDExLjk0MTcyN2wyMTYuNjA3NzA4LDBjNi43MDQyODUsMCAxMi40NzgxMTksLTUuNTc3NDIzIDEyLjQ3ODExOSwtMTMuMDE5OTEzbC0wLjA3MTE2Nyw\
        tMS40NDc2MDFjMCwtMy40NDgzMzQgLTEuNjk2NjU1LC02LjQ0MjY3MyAtMy41NTQ3NzksLTkuNTI3OTA4bC0xMDcuMjc0NjczLC0xOTIuMjcwNjM0Yy00LjczOTU3OCwtNS4yN\
        jE3ODQgLTEyLjQyMzUzOCwtNS4yNjE3ODQgLTE3LjE2Mzg0OSwwLjAwMDcxbC0xMTAuMDE2ODg0LDE5My4zNTQ1NDl6Ii8+PHBhdGggZmlsbD0iIzAwMDAwMCIgZD0ibTE1MC4\
        1OTc2ODcsMTkxLjc1NDE1YTE3LjA5MTUxNiwxNy4wNzcwMTcgMCAxIDEtMzQuMTgzMDE0LDBhMTcuMDkxNTE2LDE3LjA3NzAxNyAwIDEgMTM0LjE4MzAxNCwweiIvPjxwYXRoI\
        GZpbGw9IiMwMDAwMDAiIGQ9Im0xMzMuMzk0ODgyLDczLjEwNjYxM2M2LjcxNDYsMCAxNy4xMzU0MzcsNS4zNDUyNzYgMTcuMTM1NDM3LDExLjk4NDkwMWwtNS4wMTUyMjgsNjk\
        uMDA0MDA1YzAsNi42Mzk2NDggLTUuNDA1NjA5LDExLjk4NDkyNCAtMTIuMTIwMjA5LDExLjk4NDkyNGMtNi43MTQ2LDAgLTEyLjEyMDE5MywtNS4zNDUyNzYgLTEyLjEyMDE5M\
        ywtMTEuOTg0OTI0bC01Ljg1MTEzNSwtNjkuMDA0MDA1YzAsLTYuNjM5NjI2IDExLjI1NjcyOSwtMTEuOTg0OTAxIDE3Ljk3MTMyOSwtMTEuOTg0OTAxeiIvPjwvc3ZnPg==");
    }
    @media screen {
        html, body {
            /* First the UI fonts of WinVista+, OSX10.11, OSX10.10, OSX10.9-, WinXP-, Ubuntu. Then some fallbacks. */
            font-family: Segoe UI, San Francisco, Helvetica Neue, Lucida Grande, Tahoma, Ubuntu, Helvetica, Arial, sans-serif;
jhoogenboom's avatar
jhoogenboom committed
40
            font-size: 10pt;
jhoogenboom's avatar
jhoogenboom committed
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
        body {
            margin: 0rem;
        }
        a {
            color: inherit;
            text-decoration: inherit;
            border-bottom: 1px dotted;
        }
        a:hover {
            border-bottom: 1px solid;
        }
        a.disabled {
            color: hsl(220, 20%, 53%);
        }
        a.disabled:hover {
            color: hsl(220, 20%, 53%);
            border-bottom: 1px dotted;
            cursor: default;
        }
        #outer {
            display: flex;
            flex-flow: column nowrap;
            height: 100vh;
            overflow: hidden;
        }
        #inner {
            display: flex;
            flex-flow: row nowrap;
            flex: 1 1 auto;
            overflow: hidden;
        }
        #messagebox {
            flex: 0 0 auto;
            background-color: hsl(220, 20%, 77%);
            padding: .2rem;
            cursor: default;
        }
        #optscrollbox {
            display: flex;
            flex-flow: column nowrap;
            flex: 0 0 auto;
            width: 22.5em;
            order: -1;
            overflow: auto;
            background-color: hsl(220, 20%, 77%);
            border-right: 1px solid hsl(220, 20%, 3%);
            border-bottom: none;
            cursor: default;
jhoogenboom's avatar
jhoogenboom committed
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
        #visscrollbox {
            flex: 1 1 auto;
            overflow: auto;
            background-color: hsl(220, 20%, 97%); /* eef8ff */
            border-bottom: 1px solid hsl(220, 20%, 3%);
            text-align: right;
        }
        .optiongroup {
            flex: 0 0 auto;
            padding: .2rem .2rem 1rem;
        }
        .optiongroup:last-child {
            padding: .2rem;
        }
        .optiongroup > table {
            margin: 0rem;
            border-spacing: 0rem;
            border: none;
        }
        .optiongroup > .optionheader {
            text-align: left;
            font-weight: bold;
            text-transform: uppercase;
        }
        .optiongroup > .optionheader:first-letter {
            font-size: 1.25em;
        }
        .optiongroup > table td {
            white-space: nowrap;
        }
        .optiongroup > table td:not(:last-child) {
            padding-right: .4rem;
        }
        .optiongroup > table tr.fileselectrow, .optiongroup > table tr.filenamedisplayrow {
            display: none;
        }
        .optiongroup > table tr.filenamedisplayrow #filenamedisplay {
            max-width: 20em;
            width: auto;
        }
        .optiongroup > table td.footnote {
            font-style: italic;
            white-space: wrap;
        }
        .help {
            cursor: help;
            font-weight: bold;
            border-bottom: 1px dotted hsl(220, 20%, 3%);
        }
        #vis {
            direction: rtl;
            display: inline-block;
        }
        #vis div {
            direction: ltr;
        }
        #vis div:nth-child(2n+3) {
            border-top: 1px solid hsl(220, 20%, 3%);
            padding-top: .8rem;
            margin-top: .8rem;
        }
        #vis div:last-child {
            padding-bottom: .8rem;
        }
        .markertable {
            display: inline-table;
            text-align: left;
            border-collapse: collapse;
            max-width: 55vw;
            margin-right: 12rem;
        }
        .markertable td {
            border: 1px solid hsl(220, 20%, 57%);
            padding: .4rem;
            font-size: 0.8em;
            white-space: nowrap;
            width: .1rem;
        }
        .markertable tr:first-child td {
            font-weight: bold;
        }
        .markertable td:nth-child(2) {
            width: auto;
        }
175 176 177 178
        .markertable tr:first-child {
            background-color: hsl(220, 20%, 77%);
        }
        .markertable tr:nth-child(1n+2) {
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
            background-color: hsl(220, 20%, 97%);
        }
        .markertable tr:nth-child(2n) {
            background-color: hsl(220, 20%, 90%);
        }
        .markertable tr.removed td:not(:last-child) {
            text-decoration: line-through;
        }
        td.num {
            text-align: right;
        }
        td.wrap {
            white-space: normal !important;
            width: 1em;
        }
    }
    /*
    portrait, height >= 55:
197

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
      small collapsed   large collapsed   small top    large top
    |-----------------|-----------------|------------|------------>  width
    0                 45                60           68


    portrait, height < 55:

      small collapsed   large collapsed
    |-----------------|------------------------------------------->  width
    0                 45


    landscape:

      small collapsed   large collapsed   small left   large left
    |-----------------|-----------------|------------|------------>  width
    0                 45                60           68
    */
    @media only screen and (min-aspect-ratio: 40000/30000) and (min-width: 60em) and (max-width: 68em), /* Full menu is at the side, but viewport is not very wide */
           only screen and (max-aspect-ratio: 40000/30000) and (min-height: 55em) and (min-width: 60em) and (max-width: 68em), /* Full menus at the top, but viewport not wide enough */
           only screen and (max-width: 45em) { /* Very narrow; menu names don't fit anymore */
        /* Limited width: make menu smaller */
        #optscrollbox {
            font-size: .85em;
        }
    }
    @media only screen and (max-aspect-ratio: 40000/30000), only screen and (max-width: 60em) {
        /* Portrait or near-portrait, or rather narrow: menu at the top */
        #inner {
            flex-direction: column;
        }
        #optscrollbox {
            flex: 0 0 auto;
            flex-flow: row nowrap;
            width: 100%;
            border-right: none;
            border-bottom: 1px solid hsl(220, 20%, 3%);
        }
        #visscrollbox {
            flex: 1 1 auto;
        }
        .optiongroup {
            flex: 1 0 auto;
            padding: .2rem 1rem .2rem .2rem;
        }
    }
    @media only screen and (max-aspect-ratio: 40000/30000) and (max-height: 55em), only screen and (max-width: 60em) {
        /* Portrait or near-portrait combined with very limited height, or rather narrow: collapse menu */
        #optscrollbox {
            overflow: visible;
            z-index: 100;
            border-bottom: 1px solid hsl(220, 20%, 3%);
        }
        .optiongroup {
            position: relative;
        }
        .optiongroup > table {
            display: none;
            position: absolute;
            top: 100%;
            background-color: hsl(220, 20%, 77%);
            border: 1px solid hsl(220, 20%, 3%);
            border-top: none;
        }
        .optiongroup:last-child > table {
            left: auto;
            right: .2rem;
        }
        .optiongroup:hover > .optionheader {
            color: hsl(220, 20%, 97%);
        }
        .optiongroup:hover > table {
            display: table;
        }
    }

    @media print {
        html, body {
            font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
            font-size: 10pt;
        }
        .noprint, .help {
            display: none;
        }
        #messagebox {
            font-size: 8pt;
            padding: 5pt 0pt;
        }
        #optscrollbox {
            display: flex;
            box-sizing: border-box;
            flex-flow: row wrap;
            align-items: stretch;
            width: 100%;
            border-top: 1pt solid black;
            border-right: 1pt solid black;
294
            font-size: 7pt;
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
        }
        .optiongroup {
            flex-grow: 1;
            padding: 5pt;
            border-left: 1pt solid black;
            border-bottom: 1pt solid black;
        }
        .optiongroup > table {
            padding: 0px;
            margin: 0px;
            border-spacing: 0px;
            border: none;
        }
        .optiongroup > .optionheader {
            text-align: left;
            font-weight: bold;
            text-transform: uppercase;
        }
        .optiongroup > .optionheader:first-letter {
            font-size: 1.25em;
        }
        .optiongroup > table td {
            white-space: nowrap;
        }
        .optiongroup > table td:not(:last-child) {
            padding-right: 5pt;
        }
        .optiongroup > table td.footnote {
            font-style: italic;
            white-space: wrap;
        }
        .optiongroup > table input {
            border: none;
        }
        .optiongroup > table input[type=checkbox] {
            height: 1em;
            width: 1em;
        }
        #vis {
            width: 100%;
        }
        #vis > div {
            width: 100%;
            direction: rtl;
            text-align: right;
        }
        #vis > div > * {
            direction: ltr;
        }
        #vis > :nth-child(2n+0){
            break-before: avoid;
            page-break-before: avoid;
            page-break-inside: avoid;
        }
        #vis > :nth-child(2n+1){
            break-after: avoid;
            page-break-after: avoid;
            page-break-inside: avoid;
        }
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
354
        .vega, canvas {
355 356
            max-width: 100%;
            height: auto;
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
357 358 359 360 361 362 363
            overflow: visible;
        }
        svg {
            /* Using slightly smaller width to prevent clipping in Chrome */
            max-width: 98%;
            height: auto;
            overflow: visible;
364 365 366 367 368 369 370 371 372 373
        }
        canvas {
            object-fit: scale-down;
        }
        .markertable {
            display: inline-table;
            box-sizing: border-box;
            text-align: left;
            border-collapse: collapse;
            width: 100%;
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
374
        }
375 376 377
        .markertable td {
            border: 1pt solid #888888;
            padding: 2pt;
378
            font-size: 7pt;
379 380 381 382 383 384 385 386 387
            white-space: nowrap;
            width: 50pt;
        }
        .markertable tr:first-child td {
            font-weight: bold;
        }
        .markertable td:nth-child(2) {
            width: auto;
        }
388 389 390
        .markertable tr:first-child {
            background-color: #cccccc;
        }
391 392 393 394 395 396 397 398 399 400 401 402 403
        .markertable tr:nth-child(2n) {
            background-color: #eeeeee;
        }
        .markertable tr.removed td:not(:last-child) {
            text-decoration: line-through;
        }
        .num {
            text-align: right;
        }
        td.wrap {
            white-space: normal !important;
        }
    }
jhoogenboom's avatar
jhoogenboom committed
404 405 406
    </style>
</head>
<body>
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
<div id="outer">
<div id="inner">
    <div id="optscrollbox">
        <div class="optiongroup noprint">
            <div class="optionheader">Input &amp; output</div>
            <table>
                <tr class="fileselectrow filenamedisplayrow">
                    <td>Sample data file:</td>
                </tr>
                <tr class="fileselectrow">
                    <td><input id="fileselect" type="file"></td>
                </tr>
                <tr class="fileselectrow">
                    <td>(or drag a file onto this page)</td>
                </tr>
                <tr class="filenamedisplayrow">
                    <td id="filenamedisplay" class="wrap"></td>
                </tr>
                <tr>
                    <td>
                        <a id="saveImageLink" href="javascript:void(saveImage())" class="disabled">Save image</a>
                        <a id="saveTableLink" href="javascript:void(saveTable())" class="disabled">Save table</a>
                    </td>
                </tr>
            </table>
        </div>
        <div class="optiongroup">
            <div class="optionheader">Graph filtering options</div>
            <table>
                <tr>
                    <td colspan="2">Show sequences with at least:</td>
                </tr>
                <tr>
                    <td colspan="2"><label><input type="text" value="15" id="minN" size="3" class="num"> reads</label></td>
                </tr>
                <tr>
                    <td colspan="2"><label><input type="text" value="0.5" id="minP" size="3" class="num">% of highest allele per marker</label></td>
                </tr>
                <tr>
                    <td colspan="2"><label><input type="text" value="0" id="minT" size="3" class="num">% of the marker's total reads</label></td>
                </tr>
                <tr>
                    <td colspan="2"><label><input type="text" value="0" id="minO" size="3" class="num"> reads in both orientations</label></td>
                </tr>
                <tr>
                    <td><label for="markerFilter">Marker(s)</label></td>
                    <td>
                        <label>
                            <input type="text" id="markerFilter" size="15">
456
                            <span class="help" title="Type xyz to show all markers with 'xyz' in their names. Type =xyz to show only the marker 'xyz'. Separate multiple values with spaces.">?</span>
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
                        </label>
                    </td>
                </tr>
                <tr>
                    <td><label for="minBias">Mark with &lt;</label></td>
                    <td><label><input type="text" value="25" id="minBias" size="3" class="num">% of reads on one strand</label></td>
                </tr>
                <tr>
                    <td colspan="2">
                        <label>
                            <input type="checkbox" id="shownegative" checked>
                            Show negative alleles
                        </label>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <label>
                            <input type="checkbox" id="showother" checked>
                            Show filtered data as 'Other sequences'
                        </label>
                    </td>
                </tr>
            </table>
        </div>
        <div class="optiongroup">
            <div class="optionheader">Table filtering options</div>
            <table>
                <tr>
                    <td>Select sequences having at least:</td>
                </tr>
                <tr>
                    <td><label><input type="text" value="30" id="minNa" size="3" class="num"> reads</label></td>
                </tr>
                <tr>
                    <td><label><input type="text" value="5" id="minPa" size="3" class="num">% of highest allele per marker</label></td>
                </tr>
                <tr>
                    <td><label><input type="text" value="3" id="minTa" size="3" class="num">% of the marker's total reads</label></td>
                </tr>
                <tr>
                    <td><label><input type="text" value="0" id="minCa" size="3" class="num">% correction*</label></td>
                </tr>
                <tr>
                    <td><label><input type="text" value="0" id="minAa" size="3" class="num">% recovery*</label></td>
                </tr>
                <tr>
                    <td><label><input type="text" value="0" id="minOa" size="3" class="num"> reads in both orientations</label></td>
                </tr>
                <tr>
                    <td class="footnote">*Of these criteria, at least one must be met</td>
                </tr>
                <tr class="noprint">
                    <td><a id="clearSelectionLink" href="javascript:void(clearSelection())" class="disabled">Clear manually added/removed</a></td>
                </tr>
            </table>
        </div>
        <div class="optiongroup noprint">
            <div class="optionheader">Display options</div>
            <table>
                <tr>
518
                    <td colspan="2"><label for="graphwidth">Graph width</label></td>
519 520 521
                    <td colspan="2"><label><input type="text" value="600" id="graphwidth" size="3" class="num"> px</label></td>
                </tr>
                <tr>
522
                    <td colspan="2"><label for="barwidth">Bar width</label></td>
523 524 525
                    <td colspan="2"><label><input type="text" value="15" id="barwidth" size="3" class="num"> px</label></td>
                </tr>
                <tr>
526
                    <td colspan="2"><label for="subgraphoffset">Marker spacing</label></td>
527 528 529
                    <td colspan="2"><label><input type="text" value="70" id="subgraphoffset" size="3" class="num"> px</label></td>
                </tr>
                <tr>
530 531 532 533 534
                    <td colspan="2"><label for="subgraphoffset">Truncate sequences to</label></td>
                    <td colspan="2"><label><input type="text" value="70" id="maxseqlen" size="3" class="num"> characters</label></td>
                </tr>
                <tr>
                    <td colspan="4">
535 536 537 538 539 540 541
                        <label>
                            <input type="checkbox" id="splitmarkers" checked>
                            Split markers
                        </label>
                    </td>
                </tr>
                <tr>
542
                    <td colspan="4">
543 544 545
                        <label>
                            <input type="checkbox" id="commonrange" disabled>
                            Common axis range
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
546 547 548 549 550
                            <span class="help" title="This option is only available if 'Split markers' has been turned off.">?</span>
                        </label>
                    </td>
                </tr>
                <tr>
551
                    <td colspan="4">
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
552 553 554
                        <label>
                            <input type="checkbox" id="sortstrbylength">
                            Sort STR alleles by length
555 556 557 558 559
                        </label>
                    </td>
                </tr>
                <tr>
                    <td>Axis scale</td>
560
                    <td colspan="2"><label><input type="radio" name="scale" value="linear" id="scaleLinear" checked> Linear</label></td>
561 562 563 564
                    <td><label><input type="radio" name="scale" value="sqrt" id="scaleLog"> Square root</label></td>
                </tr>
                <tr class="noprint">
                    <td>Renderer</td>
565
                    <td colspan="2"><label><input type="radio" name="renderer" value="svg" id="renderSVG" checked> SVG</label></td>
566 567 568
                    <td><label><input type="radio" name="renderer" value="canvas" id="renderCanvas"> Canvas</label></td>
                </tr>
            </table>
jhoogenboom's avatar
jhoogenboom committed
569
        </div>
jhoogenboom's avatar
jhoogenboom committed
570
    </div>
571 572 573
    <div id="visscrollbox">
        <div id="vis"></div>
    </div>
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
</div>
<div id="messagebox">
    Ready
</div>
</div>
<script type="text/javascript">
var graphs = false;
var linebreak = "\n";
var data_format = {};
var data_values = [];
var missing_markers = [];
var fileName = "sample";
var stamp = 0;
var userSelected = [];
var userDeselected = [];
var autoSelected = [];
var selectedAlleles = []; //This keeps the alleles of filtered markers in a safe place.
var isAutoselecting = false;
function parse(maintainSelection){
    if(maintainSelection)
        selectedAlleles = selectedAlleles.concat(userSelected, userDeselected, userDeselected);
    else
        selectedAlleles = [];
    userSelected = [];
    userDeselected = [];
    autoSelected = [];
    var this_stamp = ++stamp;
    var visdiv = document.getElementById("vis");
    var scrolldiv = document.getElementById("visscrollbox");
    var rendererName = document.querySelector("input[name=renderer]:checked").value;
    graphs = [];
    removeChildren(visdiv);
    document.getElementById("saveImageLink").setAttribute("class", "disabled");
    document.getElementById("saveTableLink").setAttribute("class", "disabled");
    document.getElementById("clearSelectionLink").setAttribute("class", selectedAlleles.length? "" : "disabled");
609

610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
    //Get a list of marker names and render a graph for each of them.
    var splitMarkers = document.getElementById("splitmarkers").checked;
    var markerFilter = document.getElementById("markerFilter").value;
    var markerNames = [];
    if(splitMarkers){
        var patt = new RegExp('(?:' + markerFilter.trim().replace(/(^| )=(.*?)(?= |$)/g, '$1^$2$$').replace(/ +/g, ')|(?:') + ')');
        data_values.forEach(function(datum){
            if(patt.test(datum.marker))
                markerNames.push("=" + datum.marker);
        });
    }
    else
        markerNames.push(markerFilter);
    var prevMarker;
    markerNames.sort().forEach(function(marker){
        if(marker != prevMarker)
            prevMarker = marker;
        else
            return;
629

630 631 632 633 634 635
        //Set up graph spec for this marker.
        for(i in graph_spec.signals)
            if(graph_spec.signals[i].name == "filter_marker")
                graph_spec.signals[i].init = marker;
        var patt = new RegExp('(?:' + marker.replace(/(^| )=(.*?)(?= |$)/g, '$1^$2$$').replace(/ +/g, ')|(?:') + ')');
        graph_spec.data[0].values = data_values.filter(function(datum){return patt.test(datum.marker)});
636

637 638 639 640 641
        //Render graph for this marker.
        vg.parse.spec(graph_spec, function(chart){
            //Cancel rendering if a new parse() call was made.
            if(this_stamp != stamp)
                return;
642

643
            var i = graphs.length;
644

645 646 647 648 649 650 651
            //Add new visualisation and table divs.
            var newvis = document.createElement("div");
            newvis.setAttribute("id", "vis" + i);
            visdiv.appendChild(newvis);
            var newtab = document.createElement("div");
            newtab.setAttribute("id", "tab" + i);
            visdiv.appendChild(newtab);
652

653 654 655 656 657
            var graph = chart({el: newvis, renderer: rendererName});
            graph.onSignal("clickedAllele", function(name, value){
                if(isAutoselecting)
                    return;
                document.getElementById("clearSelectionLink").setAttribute("class", "");
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
658
                if(graph.data("selectedAlleles").values().some(function(item){return item.thedatum==value})){
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
                    //User added this allele.
                    var pos = userDeselected.indexOf(value);
                    if(pos >= 0)
                        userDeselected.splice(pos, 1);
                    if(userSelected.indexOf(value) == -1)
                        userSelected.push(value);
                }
                else{
                    //User removed this allele.
                    var pos = userSelected.indexOf(value);
                    if(pos >= 0)
                        userSelected.splice(pos, 1);
                    if(userDeselected.indexOf(value) == -1)
                        userDeselected.push(value);
                }
                updateTable(i);
            });
            graph.onSignal("bias_threshold", function(){updateTable(i)});
            graph.update();
            if(rendererName == "svg")
                updateViewBox(graph._el.childNodes[0]);
            graphs.push(graph);
            if(!splitMarkers)
                document.getElementById("saveImageLink").setAttribute("class", "");
jhoogenboom's avatar
jhoogenboom committed
683

684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
            //Restore selected and deselected alleles. Deselected alleles
            //are the ones that appear in selectedAlleles twice.
            var graphAlleles = graph.data("annotated").values();
            selectedAlleles = selectedAlleles.filter(function(sa){
                return graphAlleles.every(function(datum){
                    var prev = datum._prev;
                    sa._prev = null;
                    datum._prev = null;
                    sa._id = datum._id;
                    sa.aggr._id = datum.aggr._id;
                    sa.thedatum = null;
                    datum.thedatum = null;
                    var equal = vg.util.equal(sa, datum);
                    datum.thedatum = datum;
                    if(prev)
                        datum._prev = prev;
                    if(equal)
                        graph.signal("clickedAllele", datum).update();
                    return !equal;
703
                });
jhoogenboom's avatar
jhoogenboom committed
704 705
            });

706 707
            //Automatically select alleles using set thresholds.
            autoSelectAlleles(graph);
708

709 710 711 712 713 714 715
            //Scroll to the right; the graph is more interesting than the long labels.
            scrolldiv.scrollLeft = scrolldiv.scrollWidth;
        });
    });
    if(missing_markers.length)
        setMessage("Warning: Some markers were not detected in this sample:\n" + missing_markers.join(", "), true, "warning");
}
716

717 718 719 720
function setMessage(message, printed, messagetype){
    var messagebox = document.getElementById("messagebox");
    removeChildren(messagebox);
    messagebox.setAttribute("class", printed? "" : "noprint");
jhoogenboom's avatar
jhoogenboom committed
721

722 723 724 725 726
    if(messagetype == "warning"){
        var icon = document.createElement("span");
        icon.setAttribute("class", "icon warning");
        messagebox.appendChild(icon);
    }
jhoogenboom's avatar
jhoogenboom committed
727

728 729
    messagebox.appendChild(document.createTextNode(message));
}
jhoogenboom's avatar
jhoogenboom committed
730

731 732 733 734 735 736 737 738 739 740 741 742
function autoSelectAlleles(graph){
    if(graphs === false)
        return;
    var minNa = parseFloat(document.getElementById("minNa").value),
        minPa = parseFloat(document.getElementById("minPa").value),
        minTa = parseFloat(document.getElementById("minTa").value),
        minCa = parseFloat(document.getElementById("minCa").value),
        minAa = parseFloat(document.getElementById("minAa").value),
        minOa = parseFloat(document.getElementById("minOa").value);
    if(isNaN(minNa + minPa + minTa + minCa + minAa + minOa))
        return;
    (graph === undefined? graphs : [graph]).forEach(function(graph){
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
743
        var selectedAllelesInGraph = graph.data("selectedAlleles").values().map(function(datum){return datum.thedatum});
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
        graph.data("annotated").values().forEach(function(datum){
            if(datum.sequence != "Other sequences" &&
               datum.total_added >= minNa &&
               datum.pct_of_max >= minPa &&
               datum.pct_of_sum >= minTa &&
               ((datum.total_added/datum.total*100-100) >= minCa ||
               (datum.total_add/datum.total*100) >= minAa) &&
               Math.min(datum.forward_added, datum.reverse_added) >= minOa){
                if(autoSelected.indexOf(datum) == -1)
                    autoSelected.push(datum);
                if(selectedAllelesInGraph.indexOf(datum) == -1 && userDeselected.indexOf(datum) == -1){
                    //Meets criteria, not selected, and user has not deselected. Autoselect.
                    isAutoselecting = true;
                    graph.signal("clickedAllele", datum).update();
                    isAutoselecting = false;
jhoogenboom's avatar
jhoogenboom committed
759 760
                }
            }
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
            else{
                var pos = autoSelected.indexOf(datum);
                if(pos >= 0)
                    autoSelected.splice(pos, 1);
                if(selectedAllelesInGraph.indexOf(datum) >= 0 && userSelected.indexOf(datum) == -1){
                    //Does not meet criteria but was autoselected previously. Autodeselect.
                    isAutoselecting = true;
                    graph.signal("clickedAllele", datum).update();
                    isAutoselecting = false;
                }
            }
        });
        updateTable(graphs.indexOf(graph));
    });
}
jhoogenboom's avatar
jhoogenboom committed
776

777 778 779 780 781
function updateViewBox(svg){
    //Setting the viewBox enables shrink-to-fit behaviour when printing.
    svg.setAttribute("viewBox",
        "0 0 " + svg.getAttribute("width") + " " + svg.getAttribute("height"));
}
jhoogenboom's avatar
jhoogenboom committed
782

783 784 785 786 787
function removeChildren(el){
    while(el.lastChild){
      el.removeChild(el.lastChild);
    }
}
jhoogenboom's avatar
jhoogenboom committed
788

789 790 791 792 793 794 795 796
function setScale(value){
    if(!graph_spec)
        return;
    for(i in graph_spec.marks)
        if(graph_spec.marks[i].scales)
            for(j in graph_spec.marks[i].scales)
                if(graph_spec.marks[i].scales[j].name == "x")
                    graph_spec.marks[i].scales[j].type = value;
jhoogenboom's avatar
jhoogenboom committed
797

798 799 800
    if(graphs !== false)
        parse(true);
}
801

802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
function getScale(){
    if(!graph_spec)
        return "linear";
    for(i in graph_spec.marks)
        if(graph_spec.marks[i].scales)
            for(j in graph_spec.marks[i].scales)
                if(graph_spec.marks[i].scales[j].name == "x")
                    return graph_spec.marks[i].scales[j].type;
    return "linear";
}

function setSignalValue(signalname, value){
    if(!graph_spec)
        return;
    var scrolldiv = document.getElementById("visscrollbox");
    var scrollRight = (scrolldiv.scrollLeft >= scrolldiv.scrollWidth - scrolldiv.clientWidth);
    if(signalname == "width")
        graph_spec.width = value;
    for(i in graph_spec.signals){
        if(graph_spec.signals[i].name == signalname){
            graph_spec.signals[i].init = value;
            break;
jhoogenboom's avatar
jhoogenboom committed
824
        }
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
    }
    if(graphs !== false)
        graphs.forEach(function(graph, i){
            graph.signal(signalname, value).padding("auto").update();
            if(document.getElementById("renderSVG").checked)
                updateViewBox(graph._el.childNodes[0]);
            if(signalname == "width"){
                var tab = document.getElementById("table" + i);
                if(tab)
                    tab.style.minWidth = value + "px";
            }
        });
    if(scrollRight)
        scrolldiv.scrollLeft = scrolldiv.scrollWidth;
    return;
}
jhoogenboom's avatar
jhoogenboom committed
841

842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
function getSignalValue(signalname){
    if(!graph_spec)
        return false;
    if(signalname == "width")
        return graph_spec.width;
    for(i in graph_spec.signals)
        if(graph_spec.signals[i].name == signalname)
            return graph_spec.signals[i].init;
    return false;
}

function setRenderer(value){
    if(graphs !== false)
        graphs.forEach(function(graph){
            graph.renderer(value).update();
            if(value == "svg")
                updateViewBox(graph._el.childNodes[0]);
        });
}

function setFileName(value){
    if(!value)
        value = "sample";
    fileName = value;
    if(value == "sample")
        document.title = "Sample Visualisation - FDSTools";
    else
        document.title = value + " - Sample Visualisation - FDSTools";
}

//Load the data (input is a fileList object; only the first file is loaded).
var currentlyLoadedFile = "no/file/loaded";
function loadDataset(fileList){
    if(!graph_spec || !fileList || !fileList.length || fileList[0].name == currentlyLoadedFile)
        return;
    setMessage("Loading data file...", false);
    currentlyLoadedFile = fileList[0].name;
    var reader = new FileReader();
    reader.onload = function(e){
        if(fileList && fileList.length && fileList[0].name)
            setFileName(fileList[0].name.substr(0, fileList[0].name.lastIndexOf(".")));
        else
            setFileName(false);
        missing_markers = []
        data_values = vg.util.read(reader.result, data_format).filter(function(datum){
            if(datum.sequence == "No data"){
                missing_markers.push(datum.marker);
                return false;
890
            }
891 892 893 894 895 896 897 898
            return true;
        });
        linebreak = reader.result.match(/\r\n|\r|\n/) || linebreak;
        setMessage("Ready", false);
        parse();
    };
    reader.readAsText(fileList[0]);
}
899

900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
//Clear user selection.
function clearSelection(){
    var link = document.getElementById("clearSelectionLink");
    if(link.getAttribute("class") == "disabled")
        return false;
    graphs.forEach(function(graph){
        graph.data("selectedAlleles").remove(function(){return true});
        graph.update();
    });
    userSelected = [];
    userDeselected = [];
    selectedAlleles = [];
    autoSelectAlleles();
    link.setAttribute("class", "disabled");
}
915

916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
//Save image function.
function saveImage(){
    var link = document.getElementById("saveImageLink");
    if(link.getAttribute("class") == "disabled")
        return false;
    var imageType = document.getElementById("renderSVG").checked? "svg": "png";
    if(window.navigator.msSaveOrOpenBlob){
        //Internet Explorer has its own ways of doing things.
        var b;
        if(imageType == "svg")
            b = new Blob([graphs[0]._el.innerHTML], {type: "image/svg+xml;charset=utf-8"});
        else
            b = graphs[0]._el.firstChild.msToBlob();
        window.navigator.msSaveOrOpenBlob(b, fileName + "." + imageType);
        if(b.msClose)
            b.msClose();
    }
    else{
        link.setAttribute("href", graphs[0].toImageURL(imageType));
        link.setAttribute("download", fileName + "." + imageType);
        link.click();
        link.setAttribute("href", "javascript:void(saveImage())");
        link.removeAttribute("download");
    }
    return false;
}

//Save table function.
function saveTable(){
    var link = document.getElementById("saveTableLink");
    if(link.getAttribute("class") == "disabled")
        return false;
    var b = new Blob(
        [["marker", "sequence", "reads", "PctOfHighest", "PctOfMarker", "PctCorrected", "PctRecovery", "PctForward", "Notes"].join("\t") + linebreak +
950
            autoSelected.concat(userSelected).filter(function(datum, index, self){
951
                return self.indexOf(datum) === index; //Deduplication.
952
            }).sort(function(a, b){
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
953
                return a.rank - b.rank;
954
            }).map(function(datum){
955
                var notes = [];
956 957
                if(autoSelected.indexOf(datum) >= 0 && userDeselected.indexOf(datum) >= 0)
                    notes.push("user_removed");
958
                if(autoSelected.indexOf(datum) < 0 && userSelected.indexOf(datum) >= 0)
959 960
                    notes.push("user_added");
                if(datum.correction_flags)
961
                        notes.push(datum.correction_flags);
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988
                return [
                    datum.marker,
                    datum.sequence,
                    datum.total_added.toFixed(),
                    datum.pct_of_max.toFixed(2),
                    datum.pct_of_sum.toFixed(2),
                    (datum.total_added/datum.total*100-100).toFixed(2),
                    (datum.total_add/datum.total*100).toFixed(2),
                    datum.forwardpct.toFixed(2),
                    notes.join(",")].join("\t");
            }).join(linebreak)
        ],
        {type: "text/plain"});
    if(window.navigator.msSaveOrOpenBlob)
        window.navigator.msSaveOrOpenBlob(b, fileName + ".csv");
    else{
        var url = URL.createObjectURL(b);
        link.setAttribute("href", url);
        link.setAttribute("download", fileName + ".csv");
        link.click();
        link.setAttribute("href", "javascript:void(saveTable())");
        link.removeAttribute("download");
    }
    if(b.msClose)
        b.msClose();
    return false;
}
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
989

990
//Data table update function.
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
991 992 993 994 995
function updateAllTables(){
    if(graphs === false)
        return;
    graphs.forEach(function(graph, i){updateTable(i)});
}
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
function updateTable(i){
    if(graphs === false)
        return;
    var table = document.createElement("table");
    table.setAttribute("id", "table" + i);
    table.setAttribute("class", "markertable");
    table.style.minWidth = graphs[i].signal("width") + "px";
    var row = table.insertRow();
    row.insertCell().appendChild(document.createTextNode("Marker"));
    row.insertCell().appendChild(document.createTextNode("Allele"));
    row.insertCell().appendChild(document.createTextNode("Reads")).parentNode.setAttribute("class", "num");
    row.insertCell().appendChild(document.createTextNode("PctOfHighest")).parentNode.setAttribute("class", "num");
    row.insertCell().appendChild(document.createTextNode("PctOfMarker")).parentNode.setAttribute("class", "num");
    row.insertCell().appendChild(document.createTextNode("PctCorrected")).parentNode.setAttribute("class", "num");
    row.insertCell().appendChild(document.createTextNode("PctRecovery")).parentNode.setAttribute("class", "num");
    row.insertCell().appendChild(document.createTextNode("PctForward")).parentNode.setAttribute("class", "num");
    row.insertCell().appendChild(document.createTextNode("Notes"));
1013

1014 1015 1016 1017
    var graphAlleles = graphs[i].data("annotated").values();
    autoSelected.concat(userSelected).filter(function(datum, index, self){
        return graphAlleles.indexOf(datum) >= 0 && self.indexOf(datum) === index;
    }).sort(function(a, b){
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
1018
        return a.rank - b.rank;
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
    }).forEach(function(datum){
        row = table.insertRow();
        row.insertCell().appendChild(document.createTextNode(datum.marker));
        row.insertCell().appendChild(document.createTextNode(datum.sequence)).parentNode.setAttribute("class", "wrap");
        row.insertCell().appendChild(document.createTextNode(datum.total_added.toFixed())).parentNode.setAttribute("class", "num");
        row.insertCell().appendChild(document.createTextNode(datum.pct_of_max.toFixed(2) + "%")).parentNode.setAttribute("class", "num");
        row.insertCell().appendChild(document.createTextNode(datum.pct_of_sum.toFixed(2) + "%")).parentNode.setAttribute("class", "num");
        var corrAmount = datum.total_added/datum.total*100-100;
        row.insertCell().appendChild(document.createTextNode((corrAmount < 0? "" : "+") + corrAmount.toFixed(2) + "%")).parentNode.setAttribute("class", "num");
        row.insertCell().appendChild(document.createTextNode((datum.total_add/datum.total*100).toFixed(2) + "%")).parentNode.setAttribute("class", "num");
        var cell = row.insertCell();
        cell.appendChild(document.createTextNode(datum.forwardpct.toFixed(2) + "%"));
        cell.setAttribute("class", "num");
        if(datum.biasmark !== "")
            cell.style.backgroundColor = "#ffaaaa";
        var notes = [];
        if(autoSelected.indexOf(datum) >= 0 && userDeselected.indexOf(datum) >= 0){
            notes.push("User-removed");
            row.setAttribute("class", "removed");
        }
        if(autoSelected.indexOf(datum) < 0 && userSelected.indexOf(datum) >= 0)
            notes.push("User-added");
        if(datum.correction_flags){
            if(datum.correction_flags == "corrected_bgestimate")
                notes.push("BGCorrect-BGEstimate");
            else if(datum.correction_flags == "corrected_bghomstats")
                notes.push("BGCorrect-BGHomStats");
            else if(datum.correction_flags == "corrected_bgpredict")
                notes.push("BGCorrect-BGPredict");
            else if(datum.correction_flags == "corrected_as_background_only")
                notes.push("BGCorrect-as-background-only");
            else if(datum.correction_flags == "not_in_ref_db")
                notes.push("BGCorrect-not-in-ref-db");
            else if(datum.correction_flags == "not_corrected")
                notes.push("BGCorrect-not-corrected");
            else
                notes.push(datum.correction_flags);
        }
        row.insertCell().appendChild(document.createTextNode(notes.join(", ")));
    });
    var tabdiv = document.getElementById("tab" + i);
    removeChildren(tabdiv);
    if(table.rows.length > 1)
        tabdiv.appendChild(table);
    document.getElementById("saveTableLink").setAttribute("class", (autoSelected.length + userSelected.length? "" : "disabled"));
}
1065

1066 1067 1068 1069 1070 1071 1072 1073 1074
function onLoadSpec(has_data){
    if(!has_data){
        //Handle files from the file input.
        document.getElementById("fileselect").addEventListener('change', function(){
            loadDataset(document.getElementById("fileselect").files);
        }, false);
        var rows = document.querySelectorAll(".fileselectrow");
        for (var i = 0; i < rows.length; i++)
            rows[i].style.display = "table-row";
jhoogenboom's avatar
jhoogenboom committed
1075

1076 1077 1078 1079 1080 1081 1082 1083
        //Allow files to be dragged onto the page.
        document.addEventListener('dragover', function(evt){
            evt.stopPropagation();
            evt.preventDefault();
        }, false);
        document.addEventListener('drop', function(evt){
            evt.stopPropagation();
            evt.preventDefault();
1084

1085 1086 1087 1088 1089 1090 1091 1092
            //Try to clear the currently displayed file, then try to set
            //the drag-'n-dropped file as the selected one on the file input.
            //Both actions are not supported in all major browsers.
            document.getElementById("fileselect").value = "";
            document.getElementById("fileselect").files = evt.dataTransfer.files;
            loadDataset(evt.dataTransfer.files);
        }, false);
    }
1093

1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
    //Parse data outside of Vega.
    data_format = graph_spec.data[0].format;
    graph_spec.data[0].format = null;
    if(has_data){
        data_values = vg.util.read(graph_spec.data[0].values, data_format).filter(function(datum){
            if(datum.sequence == "No data"){
                missing_markers.push(datum.marker);
                return false;
            }
            return true;
        });
        if(graph_spec.data[0].fdstools_filename){
            var rows = document.querySelectorAll(".filenamedisplayrow");
            for (var i = 0; i < rows.length; i++)
                rows[i].style.display = "table-row";
            var cell = document.getElementById("filenamedisplay");
            removeChildren(cell);
            cell.appendChild(document.createTextNode(graph_spec.data[0].fdstools_filename));
            setFileName(graph_spec.data[0].fdstools_filename);
        }
    }
1115 1116


1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
    //Update graph when rendering mode or axis scale is changed.
    document.getElementById("renderCanvas").addEventListener('change', function(){
        setRenderer(this.value);
    }, false);
    document.getElementById("renderSVG").addEventListener('change', function(){
        setRenderer(this.value);
    }, false);
    document.getElementById("scaleLinear").addEventListener('change', function(){
        setScale(this.value);
    }, false);
    document.getElementById("scaleLog").addEventListener('change', function(){
        setScale(this.value);
    }, false);
    document.getElementById("graphwidth").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("width", value);
    }, false);
    document.getElementById("barwidth").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("barwidth", value);
    }, false);
    document.getElementById("subgraphoffset").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("subgraphoffset", value);
    }, false);
1148 1149 1150 1151 1152 1153
    document.getElementById("maxseqlen").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("max_seq_len", value);
    }, false);
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
    document.getElementById("splitmarkers").addEventListener('change', function(){
        if(graphs !== false)
            parse(true);
        document.getElementById("commonrange").disabled = this.checked;
    }, false);
    document.getElementById("commonrange").addEventListener('change', function(){
        if(!graph_spec)
            return;
        graph_spec.marks[1].scales[0].domain.data = (this.checked? "table" : undefined);
        if(graphs !== false)
            parse(true);
    }, false);
    document.getElementById("minN").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("amplitude_threshold", value);
    }, false);
    document.getElementById("minP").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("amplitude_pct_threshold", value);
    }, false);
    document.getElementById("minT").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("amplitude_markerpct_threshold", value);
    }, false);
    document.getElementById("minO").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("orientation_threshold", value);
    }, false);
    document.getElementById("markerFilter").addEventListener('change', function(){
        if(graphs !== false)
            parse(true);
    }, false);
    document.getElementById("minBias").addEventListener('change', function(){
        var value = parseFloat(this.value);
        if(isNaN(value))
            return;
        setSignalValue("bias_threshold", value);
    }, false);
    document.getElementById("shownegative").addEventListener('change', function(){
        setSignalValue("show_negative", this.checked);
    }, false);
    document.getElementById("showother").addEventListener('change', function(){
        setSignalValue("show_other", this.checked);
    }, false);
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
1206 1207 1208 1209
    document.getElementById("sortstrbylength").addEventListener('change', function(){
        setSignalValue("sort_str_by_length", this.checked);
        updateAllTables();
    }, false);
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
    document.getElementById("minNa").addEventListener('change', function(){
        if(!isNaN(parseFloat(this.value)))
            autoSelectAlleles();
    }, false);
    document.getElementById("minPa").addEventListener('change', function(){
        if(!isNaN(parseFloat(this.value)))
            autoSelectAlleles();
    }, false);
    document.getElementById("minTa").addEventListener('change', function(){
        if(!isNaN(parseFloat(this.value)))
            autoSelectAlleles();
    }, false);
    document.getElementById("minCa").addEventListener('change', function(){
        if(!isNaN(parseFloat(this.value)))
            autoSelectAlleles();
    }, false);
    document.getElementById("minAa").addEventListener('change', function(){
        if(!isNaN(parseFloat(this.value)))
            autoSelectAlleles();
    }, false);
    document.getElementById("minOa").addEventListener('change', function(){
        if(!isNaN(parseFloat(this.value)))
            autoSelectAlleles();
    }, false);
jhoogenboom's avatar
jhoogenboom committed
1234

1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
    //Sync graph_spec and display.
    if(getScale() == "linear"){
        document.getElementById("scaleLinear").checked = true;
        document.getElementById("scaleLog").checked = false;
    }
    else{
        document.getElementById("scaleLinear").checked = false;
        document.getElementById("scaleLog").checked = true;
    }
    document.getElementById("markerFilter").value = getSignalValue("filter_marker");
    document.getElementById("graphwidth").value = getSignalValue("width");
    document.getElementById("barwidth").value = getSignalValue("barwidth");
    document.getElementById("subgraphoffset").value = getSignalValue("subgraphoffset");
1248
    document.getElementById("maxseqlen").value = getSignalValue("max_seq_len");
1249 1250 1251 1252 1253 1254 1255
    document.getElementById("minN").value = getSignalValue("amplitude_threshold");
    document.getElementById("minP").value = getSignalValue("amplitude_pct_threshold");
    document.getElementById("minT").value = getSignalValue("amplitude_markerpct_threshold");
    document.getElementById("minO").value = getSignalValue("orientation_threshold");
    document.getElementById("minBias").value = getSignalValue("bias_threshold");
    document.getElementById("shownegative").checked = getSignalValue("show_negative");
    document.getElementById("showother").checked = getSignalValue("show_other");
Hoogenboom, Jerry's avatar
Hoogenboom, Jerry committed
1256
    document.getElementById("sortstrbylength").checked = getSignalValue("sort_str_by_length");
1257

1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
    setMessage("Ready", false);
    if(has_data)
        parse();
}
</script>
<!-- BEGIN_LOAD_SCRIPT -->
<script type="text/javascript">
var graph_spec = false;
setMessage("Loading graph specification...", false);
vg.util.load({url: "samplevis.json"}, function(err, result){
    graph_spec = JSON.parse(result);
    onLoadSpec(false);
});
</script>
<!-- END_LOAD_SCRIPT -->
jhoogenboom's avatar
jhoogenboom committed
1273
</body>
1274
</html>