@@ -62,6 +62,10 @@ void api_setChromosome(String chr)
62
62
browser. chr = chr;
63
63
}
64
64
65
+ void api_setShowRangeSelector (int showRangeSelector ) {
66
+ layout. setShowRangeSelector(showRangeSelector);
67
+ }
68
+
65
69
int api_getLength()
66
70
{
67
71
return layout. getViewLength();
@@ -239,9 +243,15 @@ class Layout
239
243
DrawArea area = null ;
240
244
241
245
float pxPerBp= 1 ;
246
+ float absolutePxPerBp= 1 ;
242
247
243
248
// where to display scale (0 = no display, 1 = bottom, 2 = top)
244
249
int showScale = 1 ;
250
+
251
+ // where to display range selector (0 = no display, 1 = bottom, 2 = top)
252
+ int showRangeSelector = 1 ;
253
+ int rangeSelectorHeight= 40 ;
254
+ int rangeSelectorGridCount = 10 ;
245
255
246
256
// how many vertical grid lines should be drawn
247
257
int gridLineCount = 5 ;
@@ -282,7 +292,7 @@ class Layout
282
292
if (getZoomLength() <= maximumZoomToDrawFeatures)
283
293
scale = 3 ;
284
294
laneSize = cdsHeight* scale;
285
- laneCount = floor ((this . area. height - laneMarginTop ) / laneSize);
295
+ laneCount = floor ((this . area. height - getLaneMarginTop() ) / laneSize);
286
296
lanes = new int [laneCount];
287
297
resetLanes();
288
298
}
@@ -295,30 +305,42 @@ class Layout
295
305
}
296
306
}
297
307
308
+ void setShowRangeSelector (showRangeSelector ) {
309
+ this . showRangeSelector = showRangeSelector;
310
+ initLanes();
311
+ draw ();
312
+ }
313
+
298
314
void initArea()
299
315
{
300
316
this . area = new DrawArea (marginLeft,marginTop,(width - marginLeft - marginRight),(height - marginTop - marginBottom));
301
317
}
302
318
303
319
void setViewRegion(int start, int end)
304
320
{
305
- if (zoomStart == 0 )
321
+ /* if (zoomStart == 0)
306
322
zoomStart = start;
307
323
else if (zoomStart < start)
308
324
zoomStart = start;
309
325
if (zoomEnd == 0)
310
326
zoomEnd = end;
311
327
else if (zoomEnd > end)
312
328
zoomEnd = end;
329
+ */
330
+ zoomStart = start;
331
+ zoomEnd = end;
313
332
viewStart = start;
314
333
viewEnd = end;
315
334
initPxPerBb();
335
+ fetchGenes();
316
336
}
317
337
318
338
void initPxPerBb()
319
339
{
320
340
if (this . zoomEnd - this . zoomStart != 0 )
321
341
this . pxPerBp = (float )this . area. width / (this . zoomEnd - this . zoomStart);
342
+ if (this . viewEnd - this . viewStart != 0 )
343
+ this . absolutePxPerBp = (float )this . area. width / (this . viewEnd - this . viewStart);
322
344
}
323
345
324
346
void getFreeLane (x ) {
@@ -343,6 +365,13 @@ class Layout
343
365
return vector;
344
366
}
345
367
368
+ int getLaneMarginTop () {
369
+ int top = laneMarginTop;
370
+ if (showRangeSelector != 0 )
371
+ top = top + rangeSelectorHeight;
372
+ return top;
373
+ }
374
+
346
375
int getLanePosY(int lane)
347
376
{
348
377
return area. y + laneMarginTop + (lane* laneSize);
@@ -425,6 +454,18 @@ class Layout
425
454
{
426
455
return (int )(zoomEnd - zoomStart)/ gridLineCount;
427
456
}
457
+
458
+ int getRangeSelectorGridLineBpSeperation()
459
+ {
460
+ return (int )(viewEnd - viewStart)/ rangeSelectorGridCount;
461
+ }
462
+
463
+ int getRangeSelectorHeight () {
464
+ int currentHeight= 0 ;
465
+ if (showRangeSelector != 0 )
466
+ currentHeight = rangeSelectorHeight;
467
+ return currentHeight;
468
+ }
428
469
429
470
430
471
float pxToBp(float pixel)
@@ -437,6 +478,14 @@ class Layout
437
478
return pxPerBp * bp;
438
479
}
439
480
481
+ float absolutebpToPx (int bp ) {
482
+ return absolutePxPerBp* bp;
483
+ }
484
+
485
+ float absolutepxToBp (float pixel ) {
486
+ return (float ) pixel / absolutePxPerBp;
487
+ }
488
+
440
489
int getGenomePosition(int position_px )
441
490
{
442
491
return round (pxToBp(position_px- area. x) + zoomStart);
@@ -573,6 +622,7 @@ class GenomeBrowser
573
622
void render()
574
623
{
575
624
renderControls();
625
+ renderRangeSelector();
576
626
if (genes != null )
577
627
{
578
628
for (int i = 0 ;i< genes. size();i++ )
@@ -586,6 +636,8 @@ class GenomeBrowser
586
636
}
587
637
588
638
639
+
640
+
589
641
void renderZoomArea()
590
642
{
591
643
if (layout. mouseButtonPressed == LEFT )
@@ -602,7 +654,7 @@ class GenomeBrowser
602
654
endPosition = layout. area. x;
603
655
else if (endPosition > layout. area. getEndPosX())
604
656
endPosition = layout. area. getEndPosX();
605
- rect (startPosition,layout. area. y+ 10 ,endPosition,layout. area. getEndPosY()- layout. labelScaleSize);
657
+ rect (startPosition,layout. area. y+ 10 ,endPosition,layout. area. getEndPosY()- layout. labelScaleSize - layout . getRangeSelectorHeight() );
606
658
fill (100 );
607
659
String Position = round (layout. pxToBp(startPosition- layout. area. x) + layout. zoomStart);
608
660
String zoomWidth = layout. convertToReadableBp(Math . abs(round (layout. pxToBp(startPosition- layout. area. x) - layout. pxToBp(endPosition))));
@@ -611,7 +663,7 @@ class GenomeBrowser
611
663
else
612
664
textAlign (LEFT ,BASELINE );
613
665
text (Position ,layout. mouseButtonPressedX,10 );
614
- text (zoomWidth,startPosition + Math . abs((endPosition- startPosition)/ 2 )+ textWidth (zoomWidth)/ 2 ,layout. area. getEndPosY()- layout. labelScaleSize);
666
+ text (zoomWidth,startPosition + Math . abs((endPosition- startPosition)/ 2 )+ textWidth (zoomWidth)/ 2 ,layout. area. getEndPosY()- layout. labelScaleSize - layout . getRangeSelectorHeight() );
615
667
}
616
668
}
617
669
@@ -626,7 +678,7 @@ class GenomeBrowser
626
678
layout. mousePositionX = layout. area. getEndPosX();
627
679
628
680
stroke (layout. selectionLineColor);
629
- line (layout. mousePositionX+ 0.5 ,layout. area. y,layout. mousePositionX+ 0.5 ,layout. area. height );
681
+ line (layout. mousePositionX+ 0.5 ,layout. area. y,layout. mousePositionX+ 0.5 ,layout. area. height - layout . labelScaleSize - layout . getRangeSelectorHeight() );
630
682
fill (layout. selectionLineColor);
631
683
String Position = layout. getGenomePositionFromMouse();
632
684
if ((layout. mousePositionX + textWidth (Position ) < layout. area. getEndPosX()))
@@ -636,6 +688,62 @@ class GenomeBrowser
636
688
text (Position ,layout. mousePositionX+ 0.5 ,0 );
637
689
}
638
690
}
691
+
692
+ void renderRangeSelector () {
693
+
694
+ if (layout. showRangeSelector != 0 ) {
695
+ int scaleLineY = 0 ;
696
+ int scaleTextY = 0 ;
697
+ int gridLineSeperation = layout. getRangeSelectorGridLineBpSeperation();
698
+ float gridLineSeperationPx = layout. absolutebpToPx(gridLineSeperation);
699
+ if (layout. showRangeSelector == 1 ) {
700
+ scaleTextY = layout. area. getEndPosY();
701
+ scaleLineY = scaleTextY - layout. labelScaleSize;
702
+ }
703
+ else
704
+ {
705
+ scaleTextY = layout. area. getStartPosY();
706
+ scaleLineY = scaleTextY + layout. labelScaleSize;
707
+ }
708
+ fill (0 );
709
+ stroke (150 );
710
+ textFont (layout. font,layout. labelScaleSize);
711
+ textAlign (LEFT ,BASELINE );
712
+
713
+ for (int i = 0 ;i<= layout. rangeSelectorGridCount;i++ )
714
+ {
715
+ int x = round (i* gridLineSeperationPx + layout. area. x)+ 0.5 ;
716
+ line (x,scaleLineY,x,scaleLineY- 2 );
717
+ text (round (layout. viewStart + i* gridLineSeperation),x,scaleTextY);
718
+ }
719
+ line (layout. area. x,scaleLineY+ 0.5 ,layout. area. getEndPosX(),scaleLineY+ 0.5 );
720
+
721
+ fill (100 ,20 );
722
+ noStroke ();
723
+ rectMode (CORNERS );
724
+
725
+ int y_startPosition = scaleLineY - layout. getRangeSelectorHeight()+ layout. labelScaleSize;
726
+ int y_endPosition = scaleLineY;
727
+ int l_startPosition = 0 ;
728
+ int l_endPosition = layout. absolutebpToPx(layout. zoomStart);
729
+
730
+
731
+ rect (l_startPosition,y_startPosition,l_endPosition,y_endPosition);
732
+ int r_startPosition = layout. absolutebpToPx(layout. zoomEnd);
733
+ int r_endPosition = layout. area. getEndPosX();
734
+ rect (r_startPosition,y_startPosition,r_endPosition,y_endPosition);
735
+ stroke (100 );
736
+ strokeWeight (2.2 );
737
+ line (l_startPosition,y_startPosition,
738
+ l_endPosition,y_startPosition);
739
+ line (r_startPosition,y_startPosition,
740
+ r_endPosition,y_startPosition);
741
+ line (l_endPosition,y_startPosition,l_endPosition,y_endPosition);
742
+ line (r_startPosition,y_startPosition,r_startPosition,y_endPosition);
743
+ line (l_endPosition,y_endPosition,r_startPosition,y_endPosition);
744
+ strokeWeight (1 );
745
+ }
746
+ }
639
747
640
748
void renderControls()
641
749
{
@@ -646,13 +754,13 @@ class GenomeBrowser
646
754
float gridLineSeperationPx = layout. bpToPx(gridLineSeperation);
647
755
if (layout. showScale == 1 )
648
756
{
649
- scaleTextY = layout. area. getEndPosY();
757
+ scaleTextY = layout. area. getEndPosY() - layout . getRangeSelectorHeight() ;
650
758
scaleLineY = scaleTextY - layout. labelScaleSize;
651
759
652
760
}
653
761
else
654
762
{
655
- scaleTextY = layout. area. getEndPosY();
763
+ scaleTextY = layout. area. getEndPosY() - layout . getRangeSelectorHeight() ;
656
764
scaleLineY = scaleTextY + layout. labelScaleSize;
657
765
}
658
766
fill (0 );
@@ -663,7 +771,7 @@ class GenomeBrowser
663
771
for (int i = 0 ;i<= layout. gridLineCount;i++ )
664
772
{
665
773
int x = round (i* gridLineSeperationPx + layout. area. x)+ 0.5 ;
666
- line (x,0 ,x,layout. height );
774
+ line (x,0 ,x,( layout. height - layout . getRangeSelectorHeight()) );
667
775
text (round (layout. zoomStart + i* gridLineSeperation),x,scaleTextY);
668
776
}
669
777
line (layout. area. x,scaleLineY+ 0.5 ,layout. area. getEndPosX(),scaleLineY+ 0.5 );
@@ -699,6 +807,7 @@ class GenomeBrowser
699
807
}
700
808
701
809
810
+
702
811
class Gene
703
812
{
704
813
String strand;
0 commit comments