-
Notifications
You must be signed in to change notification settings - Fork 0
/
singlefile.js
1699 lines (1466 loc) · 54 KB
/
singlefile.js
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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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
294
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
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
456
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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
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
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
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
950
951
952
953
954
955
956
957
958
959
960
961
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
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Created by jakeconway on 4/16/16.
*/
function fileSelect(file) {
var index = fileNames.indexOf(file);
var modules = singleFileContent[index];
basicStatistics(modules["BasicStatistics"]);
perBaseSequenceQuality(modules["Perbasesequencequality"]);
if (modules["Pertilesequencequality"] === undefined) {
d3.select("#container3").select("svg").remove();
document.getElementById("three").innerHTML = "";
}
else {
perTileSequenceQuality(modules["Pertilesequencequality"]);
}
perSequenceQualityScores(modules["Persequencequalityscores"]);
perBaseSequenceContent(modules["Perbasesequencecontent"]);
perSequenceGCcontent(modules["PersequenceGCcontent"]);
perBaseNContent(modules["PerbaseNcontent"]);
sequenceLengthDistribution(modules["SequenceLengthDistribution"]);
sequenceDuplicationLevels(modules["SequenceDuplicationLevels"]);
overrepresentedSequences(modules["Overrepresentedsequences"]);
if (modules["AdapterContent"] === undefined) {
d3.select("#container11").select("svg").remove();
document.getElementById("eleven").innerHTML = "";
}
else {
adapterContent(modules["AdapterContent"]);
}
if (modules["KmerContent"] === undefined) {
d3.select("#container12").select("svg").remove();
document.getElementById("twelve").innerHTML = "";
}
else {
kmerContent(modules["KmerContent"]);
}
}
function basicStatistics(basicStats) {
document.getElementById("one").innerHTML = "";
var image = basicStats[0];
basicStats = basicStats.slice(2);
var pic = document.createElement("img");
pic.src = singleFileImages[image];
pic.width = 30, pic.height = 30;
var modTitle = document.createTextNode(" Basic Statistics");
document.getElementById("one").appendChild(pic);
document.getElementById("one").appendChild(modTitle);
var splitWords = ["Filename", "type", "Encoding", "Sequences", "quality", "length", "GC"];
var replacements = ["Filename:", "type:", "Encoding:", "Sequences:", "quality:", "length:", "GC:"];
if (basicStats[4].indexOf("Sequences flagged as poor quality") === -1) {
splitWords.splice(4, 1, "Sequences");
replacements.splice(4, 1, "Sequences:");
}
var basicStatsArray = [];
for (i = 0; i < basicStats.length; i++) {
basicStatsArray[i] = {Measure: basicStats[i].replace(splitWords[i], replacements[i]).split(":")[0],
Value: basicStats[i].replace(splitWords[i], replacements[i]).split(":")[1]};
}
var bsTable = tabulate(basicStatsArray, ["Measure", "Value"], "#container1");
}
function perBaseSequenceQuality(baseQual) {
document.getElementById("two").innerHTML = "";
var image = baseQual[0];
baseQual = baseQual.slice(2);
var pic = document.createElement("img");
pic.src = singleFileImages[image];
pic.width = 30, pic.height = 30;
var modTitle = document.createTextNode(" Per base sequence quality");
document.getElementById("two").appendChild(pic);
document.getElementById("two").appendChild(modTitle);
var parameters = [], tickText = [], tickVals = [];
for (i = 0; i < baseQual.length; i++) {
baseQual[i] = baseQual[i].replace(/\s+/g, " ");
baseQual[i].split(" ");
tickVals[i] = [i + 1];
tickText[i] = String(baseQual[i].split(" ")[0]);
parameters[i] = {
base: parseInt(i + 1),
mean: baseQual[i].split(" ")[1],
median: baseQual[i].split(" ")[2],
lowerQ: baseQual[i].split(" ")[3],
upperQ: baseQual[i].split(" ")[4],
tenthP: baseQual[i].split(" ")[5],
ninetyP: baseQual[i].split(" ")[6]
};
}
var yMax = Math.max.apply(Math, parameters.map(function (parameters) {
return parameters.ninetyP;
}));
var yScale = d3.scale.linear().range([40, 500]).domain([yMax, 0]);
var xScale = d3.scale.linear().range([40, 500]).domain([0, (parameters.length + 0.5)]);
var xAxis = d3.svg.axis().scale(xScale)
.tickValues(tickVals).tickFormat(function (d, i) {
return tickText[i];
})
.ticks(10);
var yAxis = d3.svg.axis().ticks(parameters.length).scale(yScale).orient("left");
d3.select("#container2").select("svg").remove();
var vis = d3.select("#container2").append("svg")
.attr("width", 650)
.attr("height", 550);
var boxes = vis.selectAll("rect")
.data(parameters)
.enter()
.append("rect")
.attr("width", function (d) {
var x1 = d.base - 0.4;
var x2 = d.base + 0.4;
var w = xScale(x2) - xScale(x1);
return(w);
})
.attr("height", function (d) {
return (yScale(d.lowerQ) - yScale(d.upperQ));
})
.attr("y", function (d) {
return yScale(d.upperQ);
})
.attr("x", function (d) {
var x = d.base - 0.4;
return xScale(x);
})
.attr("stroke", "black")
.attr("fill", "yellow");
var medianLine = vis.selectAll("line")
.data(parameters)
.enter()
.append("line")
.attr("x1", function (d) {
var x1 = d.base - 0.4;
return xScale(x1);
})
.attr("x2", function (d) {
var x2 = (d.base + 0.4);
return xScale(x2);
})
.attr("y1", function (d) {
return yScale(d.median);
})
.attr("y2", function (d) {
return yScale(d.median);
})
.attr("stroke", "red")
.attr("stroke-opacity", 1)
.attr("fill", "none");
var errorLineLow = vis.selectAll("line.errorLow")
.data(parameters)
.enter()
.append("line")
.attr("class", "errorLow")
.attr("x1", function (d) {
return xScale(d.base);
})
.attr("x2", function (d) {
return xScale(d.base);
})
.attr("y1", function (d) {
return yScale(d.lowerQ);
})
.attr("y2", function (d) {
return yScale(d.tenthP);
})
.attr("stroke", "black")
.attr("fill", "none");
var errorLineHigh = vis.selectAll("line.errorHigh")
.data(parameters)
.enter()
.append("line")
.attr("class", "errorHigh")
.attr("x1", function (d) {
return xScale(d.base);
})
.attr("x2", function (d) {
return xScale(d.base);
})
.attr("y1", function (d) {
return yScale(d.upperQ);
})
.attr("y2", function (d) {
return yScale(d.ninetyP);
})
.attr("stroke", "black")
.attr("fill", "none");
var errorBarLow = vis.selectAll("line.eBarLow")
.data(parameters)
.enter()
.append("line")
.attr("class", "eBarLow")
.attr("y1", function (d) {
return yScale(d.tenthP);
})
.attr("y2", function (d) {
return yScale(d.tenthP);
})
.attr("x1", function (d) {
var x1 = d.base - 0.4;
return xScale(x1);
})
.attr("x2", function (d) {
var x2 = (d.base + 0.4);
return xScale(x2);
})
.attr("stroke", "black")
.attr("opacity", function (d) {
if (d.lowerQ !== d.tenthP) {
return 1;
}
else {
return 0;
}
})
.attr("fill", "none");
var errorBarHigh = vis.selectAll("line.eBarHigh")
.data(parameters)
.enter()
.append("line")
.attr("class", "eBarHigh")
.attr("y1", function (d) {
return yScale(d.ninetyP);
})
.attr("y2", function (d) {
return yScale(d.ninetyP);
})
.attr("x1", function (d) {
var x1 = d.base - 0.4;
return xScale(x1);
})
.attr("x2", function (d) {
var x2 = (d.base + 0.4);
return xScale(x2);
})
.attr("stroke", "black")
.attr("opacity", function (d) {
if (d.upperQ !== d.ninetyP) {
return 1;
}
else {
return 0;
}
})
.attr("fill", "none");
var lineGen = d3.svg.line()
.x(function (d) {
return xScale(d.base);
})
.y(function (d) {
return yScale(d.mean);
});
vis.append("path")
.attr("class", "meanLine")
.attr("d", lineGen(parameters))
.attr("stroke", "blue")
.attr("stroke-width", 2)
.attr("fill", "none");
vis.append("text")
.attr("x", 270)
.attr("y", 540)
.attr("class", "x-axis-title")
.style("text-anchor", "middle")
.text("Position in read (bp)");
vis.append("text")
.attr("x", 300)
.attr("y", 20)
.attr("class", "x-axis-title")
.style("text-anchor", "middle")
.text("Quality scores scross all bases (Sanger / Illumina encoding)");
vis.append("svg:g")
.attr("class", "axis")
.attr("transform", "translate(0," + 500 + ")")
.call(xAxis);
vis.append("svg:g")
.attr("class", "axis")
.attr("transform", "translate(" + 4 + "0)")
.call(yAxis);
}
function perTileSequenceQuality(tileQuals) {
document.getElementById("three").innerHTML = "";
var image = tileQuals[0];
tileQuals = tileQuals.slice(2);
var pic = document.createElement("img");
pic.src = singleFileImages[image];
pic.width = 30, pic.height = 30;
var modTitle = document.createTextNode(" Per tile sequence quality");
document.getElementById("three").appendChild(pic);
document.getElementById("three").appendChild(modTitle);
var parameters = [], base = [], tile = [];
for (i = 0; i < tileQuals.length; i++) {
tileQuals[i] = tileQuals[i].replace(/\s+/g, " ");
base[i] = tileQuals[i].split(" ")[1];
tile[i] = tileQuals[i].split(" ")[0];
parameters[i] = {
tile: parseInt(tileQuals[i].split(" ")[0]),
base: tileQuals[i].split(" ")[1],
mean: parseFloat(tileQuals[i].split(" ")[2])
};
}
var numOfBases = base.unique().length;
var numOfTiles = tile.unique().length;
base = base.unique();
tile = tile.unique();
var mean = [], baseTileArray = [], holderArray = [],
totalMean = [], std = [];
for (var i = 0; i < numOfBases; i++) {
var index = base[i];
for (var j = 0; j < parameters.length; j++) {
if (parameters[j].base === index) {
holderArray.push(parameters[j]);
mean.push(parameters[j].mean);
}
}
baseTileArray[i] = holderArray;
baseTileArray[i].sort(function (a, b) {
if (a.tile > b.tile) {
return 1;
}
if (a.tile < b.tile) {
return -1;
}
// a must be equal to b
return 0;
});
totalMean[i] = d3.mean(mean);
std[i] = d3.deviation(mean);
holderArray = [];
mean = [];
}
tile = tile.sort(function (a, b) {
return b - a;
});
var yScale = d3.scale.ordinal().rangePoints([40, 500]).domain(tile),
xScale = d3.scale.ordinal().rangePoints([40, 500]).domain(base);
var xAxis = d3.svg.axis().scale(xScale);
var yAxis = d3.svg.axis().scale(yScale).orient("left");
d3.select("#container3").select("svg").remove();
var vis = d3.select("#container3").append("svg")
.attr("width", 650)
.attr("height", 550);
vis.append("text")
.attr("x", 270)
.attr("y", 540)
.attr("class", "x-axis-title")
.style("text-anchor", "middle")
.text("Position in read (bp)");
vis.append("text")
.attr("x", 300)
.attr("y", 20)
.attr("class", "x-axis-title")
.style("text-anchor", "middle")
.text("Quality per tile");
vis.append("svg:g")
.attr("class", "axis")
.attr("transform", "translate(0," + 500 + ")")
.call(xAxis);
vis.append("svg:g")
.attr("class", "axis")
.attr("transform", "translate(" + 4 + "0)")
.call(yAxis);
var tileWidth = 460 / numOfBases;
var tileHeight = 460 / numOfTiles;
for (var i = 0; i < baseTileArray.length; i++) {
var colorScale = d3.scale.linear().domain([totalMean[i], (std[i] + totalMean[i])])
.range(["blue", "green", "yellow", "orange", "red"]);
var rects = vis.selectAll("rects")
.data(baseTileArray[i])
.enter()
.append("rect")
.attr("width", function () {
return tileWidth;
})
.attr("height", function () {
return tileHeight;
})
.attr("x", function (d) {
return xScale(d.base);
})
.attr("y", function (d) {
return yScale(d.tile);
})
.attr("stroke", "black")
.attr("stroke-width", 0.5)
.style("fill", function (d) {
return colorScale(d.mean);
});
}
}
function perSequenceQualityScores(qscores) {
document.getElementById("four").innerHTML = "";
var image = qscores[0];
qscores = qscores.slice(2);
var pic = document.createElement("img");
pic.src = singleFileImages[image];
pic.width = 30, pic.height = 30;
var modTitle = document.createTextNode(" Per sequence quality scores");
document.getElementById("four").appendChild(pic);
document.getElementById("four").appendChild(modTitle);
var qscoresDict = [], read = [], quality = [];
for (i = 0; i < qscores.length; i++) {
qscores[i] = qscores[i].replace(/\s+/g, " ");
read[i] = parseInt(qscores[i].split(" ")[0]);
quality[i] = qscores[i].split(" ")[1];
qscoresDict[i] = {read: parseInt(qscores[i].split(" ")[0]),
quality: qscores[i].split(" ")[1]};
}
var xMax = Math.max.apply(null, read);
var yMax = Math.max.apply(null, quality);
var xScale = d3.scale.linear().range([40, 500]).domain([0, (xMax + 1)]);
var yScale = d3.scale.linear().range([40, 500]).domain([yMax, 0]);
var xAxis = d3.svg.axis().scale(xScale);
var yAxis = d3.svg.axis().scale(yScale).orient("left");
d3.select("#container4").select("svg").remove();
var vis = d3.select("#container4").append("svg")
.attr("width", 650)
.attr("height", 550);
var lineSvg = vis.append("g");
var focus = vis.append("g").style("display", "none");
vis.append("text")
.attr("x", 370)
.attr("y", 540)
.attr("class", "x-axis-title")
.style("text-anchor", "middle")
.text("Mean Sequence Quality (Phred Score)");
vis.append("text")
.attr("x", 375)
.attr("y", 20)
.attr("class", "x-axis-title")
.style("text-anchor", "middle")
.text("Quality score distribution over all sequences");
vis.append("svg:g")
.attr("class", "axis")
.attr("transform", "translate(100," + 500 + ")")
.call(xAxis);
vis.append("svg:g")
.attr("class", "axis")
.attr("transform", "translate(" + 14 + "0)")
.call(yAxis);
var lineGen = d3.svg.line()
.x(function (d) {
return xScale(d.read);
})
.y(function (d)
{
return yScale(d.quality);
});
lineSvg.append("path")
.attr("transform", "translate(100," + 0 + ")")
.attr('d', lineGen(qscoresDict))
.attr('stroke', 'green')
.attr('stroke-width', 2)
.attr('fill', 'none')
.on("mouseover", function () {
focus.style("display", null);
})
.on("mouseout", function () {
focus.style("display", "none");
})
.on("mousemove", mousemove);
focus.append("circle")
.attr("class", "y")
.style("fill", "none")
.style("stroke", "green")
.style("stroke-width", 2)
.attr("r", 4);
focus.append("text").attr("id", "text1");
focus.append("text").attr("id", "text2");
function mousemove() {
var x = Math.round(xScale.invert(d3.mouse(this)[0]));
var y = quality[read.indexOf(x)];
focus.select("circle.y")
.attr("cx", xScale(xScale.invert(d3.mouse(this)[0])))
.attr("cy", yScale(yScale.invert(d3.mouse(this)[1])))
.attr("transform", "translate(" + 100 + ")");
focus.select("#text1")
.attr("x", (xScale(xScale.invert(d3.mouse(this)[0]))))
.attr("y", (yScale(yScale.invert(d3.mouse(this)[1]))))
.attr("text-anchor", "left")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.attr("transform", "translate(" + 0 + ")")
.html("read: " + x);
focus.select("#text2")
.attr("x", (xScale(xScale.invert(d3.mouse(this)[0]))))
.attr("y", (yScale(yScale.invert(d3.mouse(this)[1]))))
.attr("text-anchor", "left")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.attr("transform", "translate(0,10)")
.html("quality: " + y);
}
}
function perBaseSequenceContent(baseContent) {
document.getElementById("five").innerHTML = "";
var image = baseContent[0];
baseContent = baseContent.slice(2);
var pic = document.createElement("img");
pic.src = singleFileImages[image];
pic.width = 30, pic.height = 30;
var modTitle = document.createTextNode(" Per base sequence content");
document.getElementById("five").appendChild(pic);
document.getElementById("five").appendChild(modTitle);
var parameters = [], bases = [], A = [], T = [], G = [], C = [];
for (var i = 0; i < baseContent.length; i++) {
baseContent[i] = baseContent[i].replace(/\s+/g, " ");
bases[0] = "0";
bases[i + 1] = String(baseContent[i].split(" ")[0]);
parameters[i] = {
base: String(baseContent[i].split(" ")[0]),
G: parseFloat(baseContent[i].split(" ")[1]),
A: parseFloat(baseContent[i].split(" ")[2]),
T: parseFloat(baseContent[i].split(" ")[3]),
C: parseFloat(baseContent[i].split(" ")[4])
};
}
var yScale = d3.scale.linear().range([40, 500]).domain([100, 0]),
xScale = d3.scale.ordinal().rangePoints([40, 500]).domain(bases);
var xAxis = d3.svg.axis().scale(xScale);
var yAxis = d3.svg.axis().scale(yScale).orient("left");
var interactiveX = d3.scale.linear().range([40, 500])
.domain([parseFloat(parseInt(parameters[0].base)), parameters.length]);
d3.select("#container5").select("svg").remove();
var vis = d3.select("#container5").append("svg")
.attr("width", 650)
.attr("height", 550);
var focusG = vis.append("g")
.style("display", "none");
var focusA = vis.append("g")
.style("display", "none");
var focusT = vis.append("g")
.style("display", "none");
var focusC = vis.append("g")
.style("display", "none");
vis.append("text")
.attr("x", 270)
.attr("y", 540)
.attr("class", "x-axis-title")
.style("text-anchor", "middle")
.text("Position in read (bp)");
vis.append("text")
.attr("x", 300)
.attr("y", 20)
.attr("class", "x-axis-title")
.style("text-anchor", "middle")
.text("Sequence content across all bases");
focusG.append("circle")
.attr("class", "G")
.style("fill", "none")
.attr("r", 4);
focusA.append("circle")
.attr("class", "A")
.style("fill", "none")
.attr("r", 4);
focusT.append("circle")
.attr("class", "T")
.style("fill", "none")
.attr("r", 4);
focusC.append("circle")
.attr("class", "C")
.style("fill", "none")
.attr("r", 4);
focusG.append("text")
.attr("id", "Gtext1");
focusG.append("text")
.attr("id", "Gtext2");
focusA.append("text")
.attr("id", "Atext1");
focusA.append("text")
.attr("id", "Atext2");
focusT.append("text")
.attr("id", "Ttext1");
focusT.append("text")
.attr("id", "Ttext2");
focusC.append("text")
.attr("id", "Ctext1");
focusC.append("text")
.attr("id", "Ctext2");
var G_lineGen = d3.svg.line()
.x(function (d) {
return xScale(d.base);
})
.y(function (d)
{
return yScale(d.G);
});
var A_lineGen = d3.svg.line()
.x(function (d) {
return xScale(d.base);
})
.y(function (d)
{
return yScale(d.A);
});
var T_lineGen = d3.svg.line()
.x(function (d) {
return xScale(d.base);
})
.y(function (d)
{
return yScale(d.T);
});
var C_lineGen = d3.svg.line()
.x(function (d) {
return xScale(d.base);
})
.y(function (d)
{
return yScale(d.C);
});
var Gline = vis.append("path")
.attr('d', G_lineGen(parameters))
.attr('stroke', 'black')
.attr('stroke-width', 1)
.attr('fill', 'none')
.on("mouseover", function () {
focusG.style("display", null);
})
.on("mouseout", function () {
focusG.style("display", "none");
})
.on("mousemove", mousemoveG);
var Aline = vis.append("path")
.attr('d', A_lineGen(parameters))
.attr('stroke', 'green')
.attr('stroke-width', 1)
.attr('fill', 'none')
.on("mouseover", function () {
focusA.style("display", null);
})
.on("mouseout", function () {
focusA.style("display", "none");
})
.on("mousemove", mousemoveA);
var Tline = vis.append("path")
.attr('d', T_lineGen(parameters))
.attr('stroke', 'red')
.attr('stroke-width', 1)
.attr('fill', 'none')
.on("mouseover", function () {
focusT.style("display", null);
})
.on("mouseout", function () {
focusT.style("display", "none");
})
.on("mousemove", mousemoveT);
var Cline = vis.append("path")
.attr('d', C_lineGen(parameters))
.attr('stroke', 'blue')
.attr('stroke-width', 1)
.attr('fill', 'none')
.on("mouseover", function () {
focusC.style("display", null);
})
.on("mouseout", function () {
focusC.style("display", "none");
})
.on("mousemove", mousemoveC);
vis.append("svg:g")
.attr("class", "axis")
.attr("transform", "translate(0," + 500 + ")")
.call(xAxis);
vis.append("svg:g")
.attr("class", "axis")
.attr("transform", "translate(" + 4 + "0)")
.call(yAxis);
function mousemoveG() {
var index = ((Math.round(interactiveX.invert(d3.mouse(this)[0]))) - 1);
var x = parameters[index].base;
var y = parameters[index].G;
y = +y.toFixed(2);
focusG.select("circle.G")
.attr("cx", interactiveX(interactiveX.invert(d3.mouse(this)[0])))
.attr("cy", yScale(yScale.invert(d3.mouse(this)[1])))
.attr("stroke", "black")
.attr("transform", "translate(" + 0 + ")");
focusG.select("#Gtext1")
.attr("x", (interactiveX(interactiveX.invert(d3.mouse(this)[0]))))
.attr("y", (yScale(yScale.invert(d3.mouse(this)[1]))))
.attr("text-anchor", "left")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.attr("transform", "translate(25,0)")
.html("position: " + x);
focusG.select("#Gtext2")
.attr("x", (interactiveX(interactiveX.invert(d3.mouse(this)[0]))))
.attr("y", (yScale(yScale.invert(d3.mouse(this)[1]))))
.attr("text-anchor", "left")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.attr("transform", "translate(25,10)")
.html("percentage G: " + y);
}
function mousemoveA() {
var index = ((Math.round(interactiveX.invert(d3.mouse(this)[0]))) - 1);
var x = parameters[index].base;
var y = parameters[index].A;
y = +y.toFixed(2);
focusA.select("circle.A")
.attr("cx", interactiveX(interactiveX.invert(d3.mouse(this)[0])))
.attr("cy", yScale(yScale.invert(d3.mouse(this)[1])))
.attr("stroke", "green")
.attr("transform", "translate(" + 0 + ")");
focusA.select("#Atext1")
.attr("x", (interactiveX(interactiveX.invert(d3.mouse(this)[0]))))
.attr("y", (yScale(yScale.invert(d3.mouse(this)[1]))))
.attr("text-anchor", "left")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.attr("transform", "translate(25,0)")
.html("position: " + x);
focusA.select("#Atext2")
.attr("x", (interactiveX(interactiveX.invert(d3.mouse(this)[0]))))
.attr("y", (yScale(yScale.invert(d3.mouse(this)[1]))))
.attr("text-anchor", "left")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.attr("transform", "translate(25,10)")
.html("percentage A: " + y);
}
function mousemoveT() {
var index = ((Math.round(interactiveX.invert(d3.mouse(this)[0]))) - 1);
var x = parameters[index].base;
var y = parameters[index].T;
y = +y.toFixed(2);
focusT.select("circle.T")
.attr("cx", interactiveX(interactiveX.invert(d3.mouse(this)[0])))
.attr("cy", yScale(yScale.invert(d3.mouse(this)[1])))
.attr("stroke", "red")
.attr("transform", "translate(" + 0 + ")");
focusT.select("#Ttext1")
.attr("x", (interactiveX(interactiveX.invert(d3.mouse(this)[0]))))
.attr("y", (yScale(yScale.invert(d3.mouse(this)[1]))))
.attr("text-anchor", "left")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.attr("transform", "translate(25,0)")
.html("position: " + x);
focusT.select("#Ttext2")
.attr("x", (interactiveX(interactiveX.invert(d3.mouse(this)[0]))))
.attr("y", (yScale(yScale.invert(d3.mouse(this)[1]))))
.attr("text-anchor", "left")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.attr("transform", "translate(25,10)")
.html("percentage T: " + y);
}
function mousemoveC() {
var index = ((Math.round(interactiveX.invert(d3.mouse(this)[0]))) - 1);
var x = parameters[index].base;
var y = parameters[index].C;
y = +y.toFixed(2);
focusC.select("circle.C")
.attr("cx", interactiveX(interactiveX.invert(d3.mouse(this)[0])))
.attr("cy", yScale(yScale.invert(d3.mouse(this)[1])))
.attr("stroke", "blue")
.attr("transform", "translate(" + 0 + ")");
focusC.select("#Ctext1")
.attr("x", (interactiveX(interactiveX.invert(d3.mouse(this)[0]))))
.attr("y", (yScale(yScale.invert(d3.mouse(this)[1]))))
.attr("text-anchor", "left")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.attr("transform", "translate(25,0)")
.html("position: " + x);
focusC.select("#Ctext2")
.attr("x", (interactiveX(interactiveX.invert(d3.mouse(this)[0]))))
.attr("y", (yScale(yScale.invert(d3.mouse(this)[1]))))
.attr("text-anchor", "left")
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("font-weight", "bold")
.attr("fill", "black")
.attr("transform", "translate(25,10)")
.html("percentage C: " + y);
}
}
function perSequenceGCcontent(GCcontent) {
document.getElementById("six").innerHTML = "";
var image = GCcontent[0];
var GCcontent = GCcontent.slice(2);
var pic = document.createElement("img");
pic.src = singleFileImages[image];
pic.width = 30, pic.height = 30;
var modTitle = document.createTextNode(" Per sequence GC content");
document.getElementById("six").appendChild(pic);
document.getElementById("six").appendChild(modTitle);
var parameters = [], content = [], total = 0, probability = [],
expectation = [], yMax = [];
for (var i = 0; i < GCcontent.length; i++) {
GCcontent[i] = GCcontent[i].replace(/\s+/g, " ");
total = total + parseFloat(GCcontent[i].split(" ")[1]);
parameters[i] = {
GCnumber: parseInt(GCcontent[i].split(" ")[0]),
ContentCount: parseFloat(GCcontent[i].split(" ")[1]),
theoretical: 0
};
}
for (var i = 0; i < parameters.length; i++) {
probability[i] = parameters[i].ContentCount / total;
expectation[i] = probability[i] * parameters[i].GCnumber;
}
expectation = d3.sum(expectation);
var std = [];
for (var i = 0; i < parameters.length; i++) {
std[i] = Math.pow((parameters[i].GCnumber - expectation), 2);
std[i] = std[i] * probability[i];
}
std = Math.sqrt(d3.sum(std));
var n = parseFloat(1) / ((std) * (Math.sqrt(2 * Math.PI)));
var exp, numer, pdfNormValue;
var denom = 2 * (std * std);
for (var i = 0; i < parameters.length; i++) {
numer = (-(Math.pow(parameters[i].GCnumber - expectation, 2)));
exp = numer / denom;
pdfNormValue = n * (Math.pow(Math.E, exp));
parameters[i].theoretical = pdfNormValue * total;
}
yMax[0] = Math.max.apply(Math, parameters.map(function (parameters) {
return parameters.ContentCount;
}));
yMax[1] = Math.max.apply(Math, parameters.map(function (parameters) {
return parameters.theoretical;
}));
yMax = Math.max.apply(null, yMax);
var yScale = d3.scale.linear().range([40, 500]).domain([yMax, 0]),
xScale = d3.scale.linear().range([40, 500]).domain([0, parameters.length]);
var xAxis = d3.svg.axis().scale(xScale);
var yAxis = d3.svg.axis().scale(yScale).orient("left");
d3.select("#container6").select("svg").remove();
var vis = d3.select("#container6").append("svg")
.attr("width", 650)
.attr("height", 550);
var focusA = vis.append("g")
.style("display", "none");
var focusT = vis.append("g")
.style("display", "none");
focusA.append("circle")
.attr("class", "A")
.style("fill", "none")
.attr("r", 4);
focusT.append("circle")
.attr("class", "T")
.style("fill", "none")
.attr("r", 4);
focusA.append("text")
.attr("id", "Atext1");
focusA.append("text")
.attr("id", "Atext2");
focusT.append("text")
.attr("id", "Ttext1");
focusT.append("text")
.attr("id", "Ttext2");
vis.append("text")
.attr("x", 370)
.attr("y", 540)
.attr("class", "x-axis-title")
.style("text-anchor", "middle")
.text("Mean GC content (%)");
vis.append("text")