2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
* CGHChartDataModel.java |
2 |
26 Feb 07 |
jari |
3 |
* |
2 |
26 Feb 07 |
jari |
* Created on October 30, 2002, 7:34 PM |
2 |
26 Feb 07 |
jari |
5 |
*/ |
2 |
26 Feb 07 |
jari |
6 |
|
2 |
26 Feb 07 |
jari |
7 |
package org.tigr.microarray.mev.cgh.CGHDataModel; |
2 |
26 Feb 07 |
jari |
8 |
|
2 |
26 Feb 07 |
jari |
9 |
|
2 |
26 Feb 07 |
jari |
10 |
import javax.swing.event.ChangeListener; |
2 |
26 Feb 07 |
jari |
11 |
|
2 |
26 Feb 07 |
jari |
12 |
import org.tigr.microarray.mev.cgh.CGHDataObj.CGHClone; |
2 |
26 Feb 07 |
jari |
13 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
14 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
15 |
|
2 |
26 Feb 07 |
jari |
16 |
import com.klg.jclass.chart.ChartDataEvent; |
2 |
26 Feb 07 |
jari |
17 |
import com.klg.jclass.chart.ChartDataManageable; |
2 |
26 Feb 07 |
jari |
18 |
import com.klg.jclass.chart.ChartDataModel; |
2 |
26 Feb 07 |
jari |
19 |
import com.klg.jclass.chart.ChartDataSupport; |
2 |
26 Feb 07 |
jari |
20 |
import com.klg.jclass.chart.LabelledChartDataModel; |
2 |
26 Feb 07 |
jari |
21 |
|
2 |
26 Feb 07 |
jari |
22 |
/** |
2 |
26 Feb 07 |
jari |
23 |
* |
2 |
26 Feb 07 |
jari |
* @author Adam Margolin |
2 |
26 Feb 07 |
jari |
* @author Raktim Sinha |
2 |
26 Feb 07 |
jari |
26 |
*/ |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
public abstract class CGHChartDataModel extends ChartDataSupport implements ChartDataModel, LabelledChartDataModel, ChartDataManageable, ChangeListener { |
2 |
26 Feb 07 |
jari |
29 |
public static final int CHROM_LOCATION = 0; |
2 |
26 Feb 07 |
jari |
30 |
public static final int LINEAR_ORDER = 1; |
2 |
26 Feb 07 |
jari |
31 |
|
2 |
26 Feb 07 |
jari |
32 |
int xAxisPositionType = CHROM_LOCATION; |
2 |
26 Feb 07 |
jari |
33 |
boolean smoothUnconfirmed; |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
//CGHMultipleArrayDataFcd fcd; |
2 |
26 Feb 07 |
jari |
36 |
IData data; |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
CGHBrowserModelAdaptor adaptor; |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
public CGHChartDataModel(/*CGHMultipleArrayDataFcd fcd,*/ IFramework framework){ |
2 |
26 Feb 07 |
jari |
41 |
this(/*fcd,*/ framework, 0, 0); |
2 |
26 Feb 07 |
jari |
42 |
} |
2 |
26 Feb 07 |
jari |
43 |
|
2 |
26 Feb 07 |
jari |
44 |
public CGHChartDataModel(/*CGHMultipleArrayDataFcd fcd,*/ IFramework framework, int experimentIndex, int chromosomeIndex){ |
2 |
26 Feb 07 |
jari |
//this.fcd = fcd; |
2 |
26 Feb 07 |
jari |
46 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
47 |
} |
2 |
26 Feb 07 |
jari |
48 |
|
2 |
26 Feb 07 |
jari |
49 |
public com.klg.jclass.chart.ChartDataManager getChartDataManager() { |
2 |
26 Feb 07 |
jari |
50 |
return this; |
2 |
26 Feb 07 |
jari |
51 |
} |
2 |
26 Feb 07 |
jari |
52 |
|
2 |
26 Feb 07 |
jari |
53 |
public String getDataSourceName() { |
2 |
26 Feb 07 |
jari |
54 |
return ""; |
2 |
26 Feb 07 |
jari |
55 |
} |
2 |
26 Feb 07 |
jari |
56 |
|
2 |
26 Feb 07 |
jari |
57 |
/* |
2 |
26 Feb 07 |
jari |
* @return the number of experiments if viewing all experiments, 2 otherwise |
2 |
26 Feb 07 |
jari |
* representing the cy3 and cy5 experiments |
2 |
26 Feb 07 |
jari |
60 |
*/ |
2 |
26 Feb 07 |
jari |
61 |
public abstract int getNumSeries(); |
2 |
26 Feb 07 |
jari |
62 |
|
2 |
26 Feb 07 |
jari |
63 |
public String[] getPointLabels() { |
2 |
26 Feb 07 |
jari |
64 |
|
2 |
26 Feb 07 |
jari |
65 |
String[] labels = new String[adaptor.getSeriesSize()]; |
2 |
26 Feb 07 |
jari |
66 |
for(int i = 0; i < labels.length; i++){ |
2 |
26 Feb 07 |
jari |
67 |
labels[i] = data.getCloneAt(adaptor.getCloneIndex(i)).getName(); |
2 |
26 Feb 07 |
jari |
68 |
} |
2 |
26 Feb 07 |
jari |
69 |
return labels; |
2 |
26 Feb 07 |
jari |
70 |
} |
2 |
26 Feb 07 |
jari |
71 |
|
2 |
26 Feb 07 |
jari |
72 |
public abstract String[] getSeriesLabels(); |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
public double[] getXSeries(int index) { |
2 |
26 Feb 07 |
jari |
75 |
|
2 |
26 Feb 07 |
jari |
76 |
double[] xSeries = new double[getSeriesSize()]; |
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
if(adaptor.chromosomeIndex == CGHBrowserModelAdaptor.ALL_CHROMOSOMES && xAxisPositionType == CHROM_LOCATION){ |
2 |
26 Feb 07 |
jari |
79 |
return getXSeriesAllChromosomesChromLocation(xSeries); |
2 |
26 Feb 07 |
jari |
80 |
} |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
for(int i = 0; i < xSeries.length; i++){ |
2 |
26 Feb 07 |
jari |
83 |
if(xAxisPositionType == CHROM_LOCATION){ |
2 |
26 Feb 07 |
jari |
//xSeries[i] = data.getCloneAt(mapIndexToClone[i]).getStart(); |
2 |
26 Feb 07 |
jari |
85 |
xSeries[i] = data.getCloneAt(adaptor.getCloneIndex(i)).getStart(); |
2 |
26 Feb 07 |
jari |
86 |
}else if(xAxisPositionType == LINEAR_ORDER){ |
2 |
26 Feb 07 |
jari |
87 |
xSeries[i] = i; |
2 |
26 Feb 07 |
jari |
88 |
} |
2 |
26 Feb 07 |
jari |
89 |
} |
2 |
26 Feb 07 |
jari |
90 |
return xSeries; |
2 |
26 Feb 07 |
jari |
91 |
} |
2 |
26 Feb 07 |
jari |
92 |
|
2 |
26 Feb 07 |
jari |
93 |
private double[] getXSeriesAllChromosomesChromLocation(double[] xSeries){ |
2 |
26 Feb 07 |
jari |
94 |
double total = 0; |
2 |
26 Feb 07 |
jari |
95 |
|
2 |
26 Feb 07 |
jari |
96 |
int curChromIndex = 0; |
2 |
26 Feb 07 |
jari |
97 |
for(int index = 0; index < xSeries.length; index++){ |
2 |
26 Feb 07 |
jari |
98 |
int cloneIndex = adaptor.getCloneIndex(index); |
2 |
26 Feb 07 |
jari |
99 |
CGHClone clone = data.getCloneAt(cloneIndex); |
2 |
26 Feb 07 |
jari |
100 |
while(clone.getChromosomeIndex() > curChromIndex){ |
2 |
26 Feb 07 |
jari |
101 |
total += (double)data.getCloneAt(data.getNumDataPointsInChrom(curChromIndex) - 1, curChromIndex).getStart(); |
2 |
26 Feb 07 |
jari |
102 |
curChromIndex++; |
2 |
26 Feb 07 |
jari |
103 |
} |
2 |
26 Feb 07 |
jari |
104 |
|
2 |
26 Feb 07 |
jari |
105 |
xSeries[index] = (double)clone.getStart() + total; |
2 |
26 Feb 07 |
jari |
106 |
} |
2 |
26 Feb 07 |
jari |
107 |
|
2 |
26 Feb 07 |
jari |
108 |
return xSeries; |
2 |
26 Feb 07 |
jari |
109 |
} |
2 |
26 Feb 07 |
jari |
110 |
|
2 |
26 Feb 07 |
jari |
111 |
public abstract double[] getYSeries(int index); |
2 |
26 Feb 07 |
jari |
112 |
|
2 |
26 Feb 07 |
jari |
113 |
|
2 |
26 Feb 07 |
jari |
114 |
|
2 |
26 Feb 07 |
jari |
115 |
public int getSeriesSize(){ |
2 |
26 Feb 07 |
jari |
116 |
return adaptor.getSeriesSize(); |
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
119 |
|
2 |
26 Feb 07 |
jari |
120 |
|
2 |
26 Feb 07 |
jari |
121 |
|
2 |
26 Feb 07 |
jari |
122 |
public void smoothUnconfirmed(boolean smooth){ |
2 |
26 Feb 07 |
jari |
123 |
this.smoothUnconfirmed = smooth; |
2 |
26 Feb 07 |
jari |
124 |
fireChartDataEvent(ChartDataEvent.RESET, ChartDataEvent.ALL_SERIES, ChartDataEvent.ALL_POINTS); |
2 |
26 Feb 07 |
jari |
125 |
} |
2 |
26 Feb 07 |
jari |
126 |
|
2 |
26 Feb 07 |
jari |
127 |
public void setXAxisPositions(int type){ |
2 |
26 Feb 07 |
jari |
128 |
this.xAxisPositionType = type; |
2 |
26 Feb 07 |
jari |
129 |
fireChartDataEvent(ChartDataEvent.RESET, ChartDataEvent.ALL_SERIES, ChartDataEvent.ALL_POINTS); |
2 |
26 Feb 07 |
jari |
130 |
} |
2 |
26 Feb 07 |
jari |
131 |
|
2 |
26 Feb 07 |
jari |
132 |
|
2 |
26 Feb 07 |
jari |
133 |
public int getRelativeIndexOf(int absoluteIndex){ |
2 |
26 Feb 07 |
jari |
134 |
if(adaptor.chromosomeIndex == CGHBrowserModelAdaptor.ALL_CHROMOSOMES){ |
2 |
26 Feb 07 |
jari |
135 |
return absoluteIndex; |
2 |
26 Feb 07 |
jari |
136 |
}else{ |
2 |
26 Feb 07 |
jari |
137 |
return data.getRelativeIndex(absoluteIndex, adaptor.chromosomeIndex); |
2 |
26 Feb 07 |
jari |
138 |
} |
2 |
26 Feb 07 |
jari |
139 |
} |
2 |
26 Feb 07 |
jari |
140 |
|
2 |
26 Feb 07 |
jari |
141 |
public int getCloneIndex(CGHClone clone){ |
2 |
26 Feb 07 |
jari |
142 |
int absoluteCloneIndex = data.getClones().indexOf(clone); |
2 |
26 Feb 07 |
jari |
143 |
int relativeIndex = getRelativeIndexOf(absoluteCloneIndex); |
2 |
26 Feb 07 |
jari |
144 |
return adaptor.getIndexOf(relativeIndex); |
2 |
26 Feb 07 |
jari |
145 |
} |
2 |
26 Feb 07 |
jari |
146 |
|
2 |
26 Feb 07 |
jari |
147 |
public int getStartCloneIndex(CGHClone clone){ |
2 |
26 Feb 07 |
jari |
148 |
int absoluteCloneIndex = data.getClones().indexOf(clone); |
2 |
26 Feb 07 |
jari |
149 |
int relativeIndex = getRelativeIndexOf(absoluteCloneIndex); |
2 |
26 Feb 07 |
jari |
150 |
|
2 |
26 Feb 07 |
jari |
151 |
int cloneIndex = adaptor.getIndexOf(relativeIndex--); |
2 |
26 Feb 07 |
jari |
152 |
|
2 |
26 Feb 07 |
jari |
153 |
if(cloneIndex == -1){ |
2 |
26 Feb 07 |
jari |
154 |
while((cloneIndex = adaptor.getIndexOf(relativeIndex--)) == -1){ |
2 |
26 Feb 07 |
jari |
155 |
if(cloneIndex == 0){ |
2 |
26 Feb 07 |
jari |
156 |
return 0; |
2 |
26 Feb 07 |
jari |
157 |
} |
2 |
26 Feb 07 |
jari |
158 |
} |
2 |
26 Feb 07 |
jari |
159 |
return cloneIndex + 1; |
2 |
26 Feb 07 |
jari |
160 |
} |
2 |
26 Feb 07 |
jari |
161 |
return cloneIndex; |
2 |
26 Feb 07 |
jari |
162 |
} |
2 |
26 Feb 07 |
jari |
163 |
|
2 |
26 Feb 07 |
jari |
164 |
public int getStopCloneIndex(CGHClone clone){ |
2 |
26 Feb 07 |
jari |
//Look into this method |
2 |
26 Feb 07 |
jari |
166 |
try{ |
2 |
26 Feb 07 |
jari |
167 |
int absoluteCloneIndex = data.getClones().indexOf(clone); |
2 |
26 Feb 07 |
jari |
168 |
int relativeIndex = getRelativeIndexOf(absoluteCloneIndex); |
2 |
26 Feb 07 |
jari |
169 |
|
2 |
26 Feb 07 |
jari |
170 |
int cloneIndex = adaptor.getIndexOf(relativeIndex++); |
2 |
26 Feb 07 |
jari |
171 |
if(cloneIndex >= getSeriesSize() - 1){ |
2 |
26 Feb 07 |
jari |
172 |
return getSeriesSize() - 1; |
2 |
26 Feb 07 |
jari |
173 |
} |
2 |
26 Feb 07 |
jari |
174 |
|
2 |
26 Feb 07 |
jari |
175 |
if(cloneIndex == -1){ |
2 |
26 Feb 07 |
jari |
176 |
while((cloneIndex = adaptor.getIndexOf(relativeIndex++)) == -1){ |
2 |
26 Feb 07 |
jari |
177 |
if(cloneIndex >= getSeriesSize() - 1){ |
2 |
26 Feb 07 |
jari |
178 |
return getSeriesSize() - 1; |
2 |
26 Feb 07 |
jari |
179 |
} |
2 |
26 Feb 07 |
jari |
180 |
} |
2 |
26 Feb 07 |
jari |
181 |
return cloneIndex - 1; |
2 |
26 Feb 07 |
jari |
182 |
} |
2 |
26 Feb 07 |
jari |
183 |
return cloneIndex; |
2 |
26 Feb 07 |
jari |
184 |
}catch (ArrayIndexOutOfBoundsException e){ |
2 |
26 Feb 07 |
jari |
185 |
System.out.println("Chart Model getStopCloneIndex out of bounds... returning last index"); |
2 |
26 Feb 07 |
jari |
//return mapCloneToIndex[mapCloneToIndex.length - 1]; |
2 |
26 Feb 07 |
jari |
187 |
return getSeriesSize() - 1; |
2 |
26 Feb 07 |
jari |
188 |
} |
2 |
26 Feb 07 |
jari |
189 |
} |
2 |
26 Feb 07 |
jari |
190 |
|
2 |
26 Feb 07 |
jari |
191 |
public CGHClone getCloneByPosition(int position){ |
2 |
26 Feb 07 |
jari |
192 |
for(int i = 0; i < data.getNumDataPointsInChrom(adaptor.chromosomeIndex); i++){ |
2 |
26 Feb 07 |
jari |
193 |
int startIndex = data.getCloneAt(i, adaptor.chromosomeIndex).getStart(); |
2 |
26 Feb 07 |
jari |
194 |
int stopIndex = data.getCloneAt(i, adaptor.chromosomeIndex).getStop(); |
2 |
26 Feb 07 |
jari |
195 |
if(startIndex == position || stopIndex == position){ |
2 |
26 Feb 07 |
jari |
196 |
return data.getCloneAt(i, adaptor.chromosomeIndex); |
2 |
26 Feb 07 |
jari |
197 |
} |
2 |
26 Feb 07 |
jari |
198 |
} |
2 |
26 Feb 07 |
jari |
199 |
return null; |
2 |
26 Feb 07 |
jari |
200 |
} |
2 |
26 Feb 07 |
jari |
201 |
|
2 |
26 Feb 07 |
jari |
202 |
public void stateChanged(javax.swing.event.ChangeEvent changeEvent) { |
2 |
26 Feb 07 |
jari |
203 |
fireChartDataEvent(ChartDataEvent.RESET, ChartDataEvent.ALL_SERIES, ChartDataEvent.ALL_POINTS); |
2 |
26 Feb 07 |
jari |
204 |
} |
2 |
26 Feb 07 |
jari |
205 |
|
2 |
26 Feb 07 |
jari |
206 |
public void setExperimentIndex(int experimentIndex){ |
2 |
26 Feb 07 |
jari |
207 |
adaptor.setExperimentIndex(experimentIndex); |
2 |
26 Feb 07 |
jari |
208 |
} |
2 |
26 Feb 07 |
jari |
209 |
|
2 |
26 Feb 07 |
jari |
210 |
public void setChromosomeIndex(int chromosomeIndex){ |
2 |
26 Feb 07 |
jari |
211 |
adaptor.setChromosomeIndex(chromosomeIndex); |
2 |
26 Feb 07 |
jari |
212 |
} |
2 |
26 Feb 07 |
jari |
213 |
|
2 |
26 Feb 07 |
jari |
214 |
public void setCloneValueType(int cloneValueType){ |
2 |
26 Feb 07 |
jari |
215 |
adaptor.setCloneValueType(cloneValueType); |
2 |
26 Feb 07 |
jari |
216 |
} |
2 |
26 Feb 07 |
jari |
217 |
|
2 |
26 Feb 07 |
jari |
/** Getter for property adaptor. |
2 |
26 Feb 07 |
jari |
* @return Value of property adaptor. |
2 |
26 Feb 07 |
jari |
220 |
*/ |
2 |
26 Feb 07 |
jari |
221 |
public CGHBrowserModelAdaptor getAdaptor() { |
2 |
26 Feb 07 |
jari |
222 |
return adaptor; |
2 |
26 Feb 07 |
jari |
223 |
} |
2 |
26 Feb 07 |
jari |
224 |
|
2 |
26 Feb 07 |
jari |
/** Setter for property adaptor. |
2 |
26 Feb 07 |
jari |
* @param adaptor New value of property adaptor. |
2 |
26 Feb 07 |
jari |
227 |
*/ |
2 |
26 Feb 07 |
jari |
228 |
public void setAdaptor(CGHBrowserModelAdaptor adaptor) { |
2 |
26 Feb 07 |
jari |
229 |
this.adaptor = adaptor; |
2 |
26 Feb 07 |
jari |
230 |
} |
2 |
26 Feb 07 |
jari |
231 |
|
2 |
26 Feb 07 |
jari |
232 |
} |