View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2008 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-core Project
18  //
19  // ChromosomeWindow.java
20  // Since: Sep. 29, 2009
21  //
22  // $Author: yoshimura $
23  //--------------------------------------
24  package org.utgenome.graphics;
25  
26  public class ChromosomeWindow
27  {
28      private long startIndexOnChromosome;
29      private long endIndexOnChromosome;
30      private long range;
31      private int rank = -1;
32      private int leftMargin = 50;
33      
34      public ChromosomeWindow(long startIndexOnChromosome, long endIndexOnChromosome, int rank)
35      {
36          this.startIndexOnChromosome = startIndexOnChromosome;
37          this.endIndexOnChromosome = endIndexOnChromosome;
38          this.rank = rank;
39          // inclusive
40          range = width(endIndexOnChromosome, startIndexOnChromosome) + 1;
41      }
42  
43      public ChromosomeWindow(long startIndexOnChromosome, long endIndexOnChromosome)
44      {
45          this(startIndexOnChromosome, endIndexOnChromosome, -1);
46      }
47  
48      public static long width(long x1, long x2)
49      {
50          return (x1 < x2) ? x2 - x1 : x1 - x2;
51      }
52  
53      public int getXPosOnWindow(long indexOnChromosome, int canvasWidth)
54      {
55          double v = (indexOnChromosome - startIndexOnChromosome) * (double) canvasWidth;
56  
57          double v2 = v / (double) range;
58          return (int) v2 + leftMargin;
59      }
60  
61      public long getChromosomeStart()
62      {
63          return startIndexOnChromosome;
64      }    
65      public void setChromosomeStart(long startIndexOnChromosome)
66      {
67      	this.startIndexOnChromosome = startIndexOnChromosome;
68          range = width(endIndexOnChromosome, startIndexOnChromosome) + 1;
69      }
70      
71      public long getChromosomeEnd()
72      {
73          return endIndexOnChromosome;
74      }    
75      public void setChromosomeEnd(long endIndexOnChromosome)
76      {
77      	this.endIndexOnChromosome = endIndexOnChromosome;
78          range = width(endIndexOnChromosome, startIndexOnChromosome) + 1;
79      }
80      
81      public long getChromosomeRange()
82      {
83          return range;
84      }
85  
86      public int getRank()
87      {
88      	return rank;
89      }
90      public void setRank(int rank)
91      {
92      	this.rank = rank;
93      }
94      
95      public int getLeftMargin(){
96      	return leftMargin;
97      }
98      public void setLeftMargin(int leftMargin){
99      	this.leftMargin = leftMargin;
100     }
101     
102     public long getRange(){
103     	return range;
104     }
105 }