2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
* FlankingRegionCalculator.java |
2 |
26 Feb 07 |
jari |
3 |
* |
2 |
26 Feb 07 |
jari |
* Created on December 26, 2002, 9:25 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.CGHDataGenerator; |
2 |
26 Feb 07 |
jari |
8 |
|
2 |
26 Feb 07 |
jari |
9 |
import java.util.ArrayList; |
2 |
26 Feb 07 |
jari |
10 |
import java.util.Iterator; |
2 |
26 Feb 07 |
jari |
11 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
12 |
|
2 |
26 Feb 07 |
jari |
13 |
import org.tigr.microarray.mev.ISlideData; |
2 |
26 Feb 07 |
jari |
14 |
import org.tigr.microarray.mev.MultipleArrayData; |
2 |
26 Feb 07 |
jari |
15 |
import org.tigr.microarray.mev.cgh.CGHDataObj.CGHClone; |
2 |
26 Feb 07 |
jari |
16 |
import org.tigr.microarray.mev.cgh.CGHDataObj.FlankingRegion; |
2 |
26 Feb 07 |
jari |
17 |
import org.tigr.microarray.mev.cluster.gui.ICGHCloneValueMenu; |
2 |
26 Feb 07 |
jari |
18 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
19 |
|
2 |
26 Feb 07 |
jari |
20 |
/** |
2 |
26 Feb 07 |
jari |
21 |
* |
2 |
26 Feb 07 |
jari |
* @author Adam Margolin |
2 |
26 Feb 07 |
jari |
* @author Raktim Sinha |
2 |
26 Feb 07 |
jari |
24 |
*/ |
2 |
26 Feb 07 |
jari |
25 |
|
2 |
26 Feb 07 |
jari |
26 |
public class FlankingRegionCalculator { |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
ArrayList experiments; |
2 |
26 Feb 07 |
jari |
//CGHMultipleArrayDataFcd fcd; |
2 |
26 Feb 07 |
jari |
30 |
IData data; |
2 |
26 Feb 07 |
jari |
31 |
int copyDeterminationType = ICGHCloneValueMenu.CLONE_VALUE_DISCRETE_DETERMINATION; |
2 |
26 Feb 07 |
jari |
32 |
int experimentIndex; |
2 |
26 Feb 07 |
jari |
/** Creates a new instance of FlankingRegionCalculator */ |
2 |
26 Feb 07 |
jari |
34 |
public FlankingRegionCalculator() { |
2 |
26 Feb 07 |
jari |
35 |
} |
2 |
26 Feb 07 |
jari |
36 |
|
2 |
26 Feb 07 |
jari |
37 |
public void calculateFlankingRegions(){ |
2 |
26 Feb 07 |
jari |
38 |
Iterator it = experiments.iterator(); |
2 |
26 Feb 07 |
jari |
39 |
int counter = 0; |
2 |
26 Feb 07 |
jari |
40 |
while(it.hasNext()){ |
2 |
26 Feb 07 |
jari |
41 |
this.experimentIndex = counter; |
2 |
26 Feb 07 |
jari |
42 |
calculateSampleFlankingRegions(experimentIndex, (/*ICGHFeatureData*/ISlideData)it.next()); |
2 |
26 Feb 07 |
jari |
43 |
counter++; |
2 |
26 Feb 07 |
jari |
44 |
} |
2 |
26 Feb 07 |
jari |
//Raktim |
2 |
26 Feb 07 |
jari |
//System.out.println("Experiments Counter " + counter); |
2 |
26 Feb 07 |
jari |
47 |
} |
2 |
26 Feb 07 |
jari |
48 |
|
2 |
26 Feb 07 |
jari |
49 |
private void calculateSampleFlankingRegions(int experimentIndex, /*ICGHFeatureData*/ ISlideData flank){ |
2 |
26 Feb 07 |
jari |
50 |
Vector[] sampleFlankingRegions = new Vector[data.getNumChromosomes()]; |
2 |
26 Feb 07 |
jari |
51 |
for(int i = 0; i < sampleFlankingRegions.length; i++){ |
2 |
26 Feb 07 |
jari |
52 |
sampleFlankingRegions[i] = calculateChromosomeSampleFlankingRegions(experimentIndex, i); |
2 |
26 Feb 07 |
jari |
53 |
} |
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
flank.setFlankingRegions(sampleFlankingRegions); |
2 |
26 Feb 07 |
jari |
56 |
} |
2 |
26 Feb 07 |
jari |
57 |
|
2 |
26 Feb 07 |
jari |
58 |
private Vector calculateChromosomeSampleFlankingRegions(int experimentIndex, int chromosomeIndex){ |
2 |
26 Feb 07 |
jari |
59 |
Vector flankingRegions = new Vector(); |
2 |
26 Feb 07 |
jari |
60 |
/** |
2 |
26 Feb 07 |
jari |
* Raktim |
2 |
26 Feb 07 |
jari |
* Need not calculate num Of Data Pts for each experiment for normalized ratios. |
2 |
26 Feb 07 |
jari |
* The assumption there is all samples will have the same num of data points for |
2 |
26 Feb 07 |
jari |
* each chromosome. |
2 |
26 Feb 07 |
jari |
* Do this once in the previous function |
2 |
26 Feb 07 |
jari |
66 |
*/ |
2 |
26 Feb 07 |
jari |
67 |
int numDataPts = data.getNumDataPointsInChrom(chromosomeIndex); |
2 |
26 Feb 07 |
jari |
//System.out.println("Chr Samp Flank Regions: " + experimentIndex + ", " + chromosomeIndex + ", " + numDataPts); |
2 |
26 Feb 07 |
jari |
69 |
for(int cloneIndex = 0; cloneIndex < numDataPts; cloneIndex++){ |
2 |
26 Feb 07 |
jari |
//for(int cloneIndex = 0; cloneIndex < fcd.getData().getNumDataPointsInChrom(chromosomeIndex); cloneIndex++){ |
2 |
26 Feb 07 |
jari |
71 |
int copyNumber = getCopyNumberDetermination(experimentIndex, cloneIndex, chromosomeIndex); |
2 |
26 Feb 07 |
jari |
//System.out.println("Chr Samp Flank Regions: " + experimentIndex + ", " + cloneIndex + ", " + chromosomeIndex + ", " + copyNumber); |
2 |
26 Feb 07 |
jari |
73 |
if(copyNumber != IData.NO_COPY_CHANGE && copyNumber != IData.BAD_CLONE){ //clone is not normal so this begins a flanking region |
2 |
26 Feb 07 |
jari |
74 |
int flankingRegionStart = findFlankingRegionStart(experimentIndex, cloneIndex, chromosomeIndex); |
2 |
26 Feb 07 |
jari |
75 |
CGHClone flankingRegionStartClone = findFlankingRegionStartClone(cloneIndex, chromosomeIndex); |
2 |
26 Feb 07 |
jari |
76 |
FlankingRegion curFlankingRegion = new FlankingRegion(); |
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
if(copyNumber < -1){ |
2 |
26 Feb 07 |
jari |
79 |
curFlankingRegion.setType(FlankingRegion.DELETION); |
2 |
26 Feb 07 |
jari |
80 |
curFlankingRegion.setSpecifier(FlankingRegion.DELETION_2_COPY); |
2 |
26 Feb 07 |
jari |
81 |
cloneIndex = calculateFlankingRegionEnd(experimentIndex, cloneIndex, chromosomeIndex, copyNumber); |
2 |
26 Feb 07 |
jari |
//}else if(copyNumber == 1){ |
2 |
26 Feb 07 |
jari |
83 |
}else if(copyNumber < 0){ |
2 |
26 Feb 07 |
jari |
84 |
if(copyNumber != -1){ |
2 |
26 Feb 07 |
jari |
85 |
System.out.println("FLCalc copy num < 0 = " + copyNumber); |
2 |
26 Feb 07 |
jari |
86 |
} |
2 |
26 Feb 07 |
jari |
87 |
curFlankingRegion.setType(FlankingRegion.DELETION); |
2 |
26 Feb 07 |
jari |
88 |
curFlankingRegion.setSpecifier(FlankingRegion.DELETION_1_COPY); |
2 |
26 Feb 07 |
jari |
89 |
cloneIndex = calculateFlankingRegionEnd(experimentIndex, cloneIndex, chromosomeIndex, copyNumber); |
2 |
26 Feb 07 |
jari |
90 |
}else if(copyNumber > 1){ |
2 |
26 Feb 07 |
jari |
91 |
curFlankingRegion.setType(FlankingRegion.AMPLIFICATION); |
2 |
26 Feb 07 |
jari |
92 |
curFlankingRegion.setSpecifier(FlankingRegion.AMPLIFICATION_2_COPY); |
2 |
26 Feb 07 |
jari |
93 |
cloneIndex = calculateFlankingRegionEnd(experimentIndex, cloneIndex, chromosomeIndex, copyNumber); |
2 |
26 Feb 07 |
jari |
94 |
}else if(copyNumber > 0){ |
2 |
26 Feb 07 |
jari |
95 |
curFlankingRegion.setType(FlankingRegion.AMPLIFICATION); |
2 |
26 Feb 07 |
jari |
96 |
curFlankingRegion.setSpecifier(FlankingRegion.AMPLIFICATION_1_COPY); |
2 |
26 Feb 07 |
jari |
97 |
cloneIndex = calculateFlankingRegionEnd(experimentIndex, cloneIndex, chromosomeIndex, copyNumber); |
2 |
26 Feb 07 |
jari |
98 |
} |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
int flankingRegionStop = findFlankingRegionStop(cloneIndex, chromosomeIndex); |
2 |
26 Feb 07 |
jari |
101 |
CGHClone flankingRegionStopClone = findFlankingRegionStopClone(cloneIndex, chromosomeIndex); |
2 |
26 Feb 07 |
jari |
102 |
|
2 |
26 Feb 07 |
jari |
103 |
curFlankingRegion.setStart(flankingRegionStart); |
2 |
26 Feb 07 |
jari |
104 |
curFlankingRegion.setStop(flankingRegionStop); |
2 |
26 Feb 07 |
jari |
105 |
curFlankingRegion.setChromosome(chromosomeIndex); |
2 |
26 Feb 07 |
jari |
106 |
curFlankingRegion.setStartClone(flankingRegionStartClone); |
2 |
26 Feb 07 |
jari |
107 |
curFlankingRegion.setStopClone(flankingRegionStopClone); |
2 |
26 Feb 07 |
jari |
108 |
|
2 |
26 Feb 07 |
jari |
109 |
flankingRegions.add(curFlankingRegion); |
2 |
26 Feb 07 |
jari |
110 |
} |
2 |
26 Feb 07 |
jari |
111 |
} |
2 |
26 Feb 07 |
jari |
112 |
|
2 |
26 Feb 07 |
jari |
113 |
return flankingRegions; |
2 |
26 Feb 07 |
jari |
114 |
} |
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
116 |
|
2 |
26 Feb 07 |
jari |
117 |
private int findFlankingRegionStart(int experimentIndex, int cloneIndex, int chromosomeIndex){ |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
119 |
if(cloneIndex == 0){ |
2 |
26 Feb 07 |
jari |
120 |
return 0; |
2 |
26 Feb 07 |
jari |
121 |
} |
2 |
26 Feb 07 |
jari |
122 |
|
2 |
26 Feb 07 |
jari |
123 |
while(getCopyNumberDetermination(experimentIndex, cloneIndex - 1, chromosomeIndex) == IData.BAD_CLONE){ |
2 |
26 Feb 07 |
jari |
124 |
cloneIndex--; |
2 |
26 Feb 07 |
jari |
125 |
if(cloneIndex == 0){ |
2 |
26 Feb 07 |
jari |
126 |
break; |
2 |
26 Feb 07 |
jari |
127 |
} |
2 |
26 Feb 07 |
jari |
128 |
} |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
|
2 |
26 Feb 07 |
jari |
131 |
if(cloneIndex != 0){ |
2 |
26 Feb 07 |
jari |
132 |
return data.getCloneAt(cloneIndex - 1, chromosomeIndex).getStop(); |
2 |
26 Feb 07 |
jari |
133 |
}else{ |
2 |
26 Feb 07 |
jari |
134 |
return data.getCloneAt(cloneIndex, chromosomeIndex).getStart(); |
2 |
26 Feb 07 |
jari |
135 |
} |
2 |
26 Feb 07 |
jari |
136 |
|
2 |
26 Feb 07 |
jari |
137 |
} |
2 |
26 Feb 07 |
jari |
138 |
|
2 |
26 Feb 07 |
jari |
139 |
|
2 |
26 Feb 07 |
jari |
140 |
private CGHClone findFlankingRegionStartClone(int cloneIndex, int chromosomeIndex){ |
2 |
26 Feb 07 |
jari |
//if(cloneIndex != 0){ |
2 |
26 Feb 07 |
jari |
// return fcd.getData().getCloneAt(cloneIndex - 1, chromosomeIndex); |
2 |
26 Feb 07 |
jari |
//}else{ |
2 |
26 Feb 07 |
jari |
144 |
return data.getCloneAt(cloneIndex, chromosomeIndex); |
2 |
26 Feb 07 |
jari |
145 |
//} |
2 |
26 Feb 07 |
jari |
146 |
} |
2 |
26 Feb 07 |
jari |
147 |
|
2 |
26 Feb 07 |
jari |
148 |
private int findFlankingRegionStop(int cloneIndex, int chromosomeIndex){ |
2 |
26 Feb 07 |
jari |
149 |
if(cloneIndex + 1 < data.getNumDataPointsInChrom(chromosomeIndex)){ |
2 |
26 Feb 07 |
jari |
150 |
return data.getCloneAt(cloneIndex + 1, chromosomeIndex).getStart(); |
2 |
26 Feb 07 |
jari |
151 |
}else{ |
2 |
26 Feb 07 |
jari |
152 |
return data.getCloneAt(cloneIndex, chromosomeIndex).getStop(); |
2 |
26 Feb 07 |
jari |
153 |
} |
2 |
26 Feb 07 |
jari |
154 |
} |
2 |
26 Feb 07 |
jari |
155 |
|
2 |
26 Feb 07 |
jari |
156 |
private CGHClone findFlankingRegionStopClone(int cloneIndex, int chromosomeIndex){ |
2 |
26 Feb 07 |
jari |
//if(cloneIndex + 1 < fcd.getData().getNumDataPointsInChrom(chromosomeIndex)){ |
2 |
26 Feb 07 |
jari |
// return fcd.getData().getCloneAt(cloneIndex + 1, chromosomeIndex); |
2 |
26 Feb 07 |
jari |
//}else{ |
2 |
26 Feb 07 |
jari |
160 |
return data.getCloneAt(cloneIndex, chromosomeIndex); |
2 |
26 Feb 07 |
jari |
161 |
//} |
2 |
26 Feb 07 |
jari |
162 |
} |
2 |
26 Feb 07 |
jari |
163 |
|
2 |
26 Feb 07 |
jari |
164 |
|
2 |
26 Feb 07 |
jari |
165 |
private int calculateFlankingRegionEnd(int experimentIndex, int cloneIndex, int chromosomeIndex, int flCopyNumber){ |
2 |
26 Feb 07 |
jari |
166 |
int copyNumber = 0; |
2 |
26 Feb 07 |
jari |
167 |
int numDataPts = data.getNumDataPointsInChrom(chromosomeIndex); |
2 |
26 Feb 07 |
jari |
168 |
while(cloneIndex + 1 < numDataPts && |
2 |
26 Feb 07 |
jari |
169 |
getCopyNumberDetermination(experimentIndex, cloneIndex + 1, chromosomeIndex) == flCopyNumber){ |
2 |
26 Feb 07 |
jari |
170 |
|
2 |
26 Feb 07 |
jari |
171 |
cloneIndex++; |
2 |
26 Feb 07 |
jari |
172 |
} |
2 |
26 Feb 07 |
jari |
173 |
|
2 |
26 Feb 07 |
jari |
174 |
copyNumber = getCopyNumberDetermination(experimentIndex, cloneIndex + 1, chromosomeIndex); |
2 |
26 Feb 07 |
jari |
175 |
|
2 |
26 Feb 07 |
jari |
176 |
if(cloneIndex + 1 >= numDataPts){ |
2 |
26 Feb 07 |
jari |
177 |
return cloneIndex; |
2 |
26 Feb 07 |
jari |
178 |
} |
2 |
26 Feb 07 |
jari |
179 |
|
2 |
26 Feb 07 |
jari |
180 |
if(copyNumber == IData.BAD_CLONE){ |
2 |
26 Feb 07 |
jari |
181 |
return calculateFlankingRegionEnd(experimentIndex, cloneIndex + 1, chromosomeIndex, flCopyNumber); |
2 |
26 Feb 07 |
jari |
182 |
}else{ |
2 |
26 Feb 07 |
jari |
183 |
return cloneIndex; |
2 |
26 Feb 07 |
jari |
184 |
} |
2 |
26 Feb 07 |
jari |
185 |
} |
2 |
26 Feb 07 |
jari |
186 |
|
2 |
26 Feb 07 |
jari |
187 |
|
2 |
26 Feb 07 |
jari |
188 |
private int getCopyNumberDetermination(int experimentIndex, int cloneIndex, int chromosomeIndex){ |
2 |
26 Feb 07 |
jari |
//Raktim |
2 |
26 Feb 07 |
jari |
//System.out.println("copyDeterminationType: " + copyDeterminationType); |
2 |
26 Feb 07 |
jari |
191 |
if(copyDeterminationType == ICGHCloneValueMenu.FLANKING_REGIONS_BY_THRESHOLD){ |
2 |
26 Feb 07 |
jari |
192 |
return ((MultipleArrayData)data).getCopyNumberDetermination(experimentIndex, cloneIndex, chromosomeIndex); |
2 |
26 Feb 07 |
jari |
193 |
}else if(copyDeterminationType == ICGHCloneValueMenu.FLANKING_REGIONS_BY_LOG_CLONE_DISTRIBUTION){ |
2 |
26 Feb 07 |
jari |
//Raktim. May be not needed ? |
2 |
26 Feb 07 |
jari |
195 |
return ((MultipleArrayData)data).getCopyNumberDeterminationByLogCloneDistribution(experimentIndex, data.getCloneIndex(cloneIndex, chromosomeIndex)); |
2 |
26 Feb 07 |
jari |
196 |
}else if(copyDeterminationType == ICGHCloneValueMenu.FLANKING_REGIONS_BY_THRESHOLD_OR_CLONE_DISTRIBUTION){ |
2 |
26 Feb 07 |
jari |
//Raktim. May be not needed ? |
2 |
26 Feb 07 |
jari |
198 |
return ((MultipleArrayData)data).getCopyNumberDeterminationByThresholdOrCloneDistribution(experimentIndex, data.getCloneIndex(cloneIndex, chromosomeIndex)); |
2 |
26 Feb 07 |
jari |
199 |
}else{ |
2 |
26 Feb 07 |
jari |
200 |
return IData.NO_COPY_CHANGE; |
2 |
26 Feb 07 |
jari |
201 |
} |
2 |
26 Feb 07 |
jari |
202 |
} |
2 |
26 Feb 07 |
jari |
203 |
|
2 |
26 Feb 07 |
jari |
/** Getter for property experiments. |
2 |
26 Feb 07 |
jari |
* @return Value of property experiments. |
2 |
26 Feb 07 |
jari |
206 |
*/ |
2 |
26 Feb 07 |
jari |
207 |
public java.util.ArrayList getExperiments() { |
2 |
26 Feb 07 |
jari |
208 |
return experiments; |
2 |
26 Feb 07 |
jari |
209 |
} |
2 |
26 Feb 07 |
jari |
210 |
|
2 |
26 Feb 07 |
jari |
/** Setter for property experiments. |
2 |
26 Feb 07 |
jari |
* @param experiments New value of property experiments. |
2 |
26 Feb 07 |
jari |
213 |
*/ |
2 |
26 Feb 07 |
jari |
214 |
public void setExperiments(java.util.ArrayList experiments) { |
2 |
26 Feb 07 |
jari |
215 |
this.experiments = experiments; |
2 |
26 Feb 07 |
jari |
216 |
} |
2 |
26 Feb 07 |
jari |
217 |
|
2 |
26 Feb 07 |
jari |
/** Getter for property fcd. |
2 |
26 Feb 07 |
jari |
* @return Value of property fcd. |
2 |
26 Feb 07 |
jari |
220 |
*/ |
2 |
26 Feb 07 |
jari |
//public CGHMultipleArrayDataFcd getFcd() { |
2 |
26 Feb 07 |
jari |
222 |
public IData getData() { |
2 |
26 Feb 07 |
jari |
223 |
return this.data; |
2 |
26 Feb 07 |
jari |
224 |
} |
2 |
26 Feb 07 |
jari |
225 |
|
2 |
26 Feb 07 |
jari |
/** Setter for property fcd. |
2 |
26 Feb 07 |
jari |
* @param fcd New value of property fcd. |
2 |
26 Feb 07 |
jari |
228 |
*/ |
2 |
26 Feb 07 |
jari |
//public void setFcd(CGHMultipleArrayDataFcd fcd) { |
2 |
26 Feb 07 |
jari |
230 |
public void setData(IData dat) { |
2 |
26 Feb 07 |
jari |
231 |
this.data = dat; |
2 |
26 Feb 07 |
jari |
232 |
} |
2 |
26 Feb 07 |
jari |
233 |
|
2 |
26 Feb 07 |
jari |
/** Getter for property copyDeterminationType. |
2 |
26 Feb 07 |
jari |
* @return Value of property copyDeterminationType. |
2 |
26 Feb 07 |
jari |
236 |
*/ |
2 |
26 Feb 07 |
jari |
237 |
public int getCopyDeterminationType() { |
2 |
26 Feb 07 |
jari |
238 |
return copyDeterminationType; |
2 |
26 Feb 07 |
jari |
239 |
} |
2 |
26 Feb 07 |
jari |
240 |
|
2 |
26 Feb 07 |
jari |
/** Setter for property copyDeterminationType. |
2 |
26 Feb 07 |
jari |
* @param copyDeterminationType New value of property copyDeterminationType. |
2 |
26 Feb 07 |
jari |
243 |
*/ |
2 |
26 Feb 07 |
jari |
244 |
public void setCopyDeterminationType(int copyDeterminationType) { |
2 |
26 Feb 07 |
jari |
245 |
this.copyDeterminationType = copyDeterminationType; |
2 |
26 Feb 07 |
jari |
246 |
} |
2 |
26 Feb 07 |
jari |
247 |
|
2 |
26 Feb 07 |
jari |
248 |
} |