|
1
|
|
package baseCode.bio.geneset;
|
|
2
|
|
|
|
3
|
|
import java.io.BufferedInputStream;
|
|
4
|
|
import java.io.BufferedReader;
|
|
5
|
|
import java.io.FileInputStream;
|
|
6
|
|
import java.io.IOException;
|
|
7
|
|
import java.io.InputStream;
|
|
8
|
|
import java.io.InputStreamReader;
|
|
9
|
|
import java.io.Writer;
|
|
10
|
|
import java.util.ArrayList;
|
|
11
|
|
import java.util.Collection;
|
|
12
|
|
import java.util.Collections;
|
|
13
|
|
import java.util.Comparator;
|
|
14
|
|
import java.util.HashMap;
|
|
15
|
|
import java.util.HashSet;
|
|
16
|
|
import java.util.Iterator;
|
|
17
|
|
import java.util.LinkedHashMap;
|
|
18
|
|
import java.util.List;
|
|
19
|
|
import java.util.Map;
|
|
20
|
|
import java.util.Set;
|
|
21
|
|
import java.util.StringTokenizer;
|
|
22
|
|
import java.util.Vector;
|
|
23
|
|
|
|
24
|
|
import javax.swing.table.AbstractTableModel;
|
|
25
|
|
import javax.swing.table.TableModel;
|
|
26
|
|
|
|
27
|
|
import baseCode.util.FileTools;
|
|
28
|
|
import baseCode.util.StatusViewer;
|
|
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
|
|
public class GeneAnnotations {
|
|
77
|
|
|
|
78
|
|
|
|
79
|
|
|
|
80
|
|
|
|
81
|
|
private static final int PRACTICAL_MAXIMUM_GENESET_SIZE = 1000;
|
|
82
|
|
|
|
83
|
|
|
|
84
|
|
|
|
85
|
|
|
|
86
|
|
private static final int ABSOLUTE_MINIMUM_GENESET_SIZE = 2;
|
|
87
|
|
|
|
88
|
|
private Map probeToGeneSetMap;
|
|
89
|
|
private Map geneSetToProbeMap;
|
|
90
|
|
private Map probeToGeneName;
|
|
91
|
|
private Map probeToDescription;
|
|
92
|
|
private Map geneToProbeList;
|
|
93
|
|
private Map geneToGeneSetMap;
|
|
94
|
|
private Map geneSetToGeneMap;
|
|
95
|
|
|
|
96
|
|
|
|
97
|
|
private Vector sortedGeneSets;
|
|
98
|
|
private Map geneSetToRedundantMap;
|
|
99
|
|
Vector selectedProbes;
|
|
100
|
|
private Vector selectedSets;
|
|
101
|
|
|
|
102
|
|
private StatusViewer messenger;
|
|
103
|
|
|
|
104
|
|
|
|
105
|
|
|
|
106
|
|
|
|
107
|
|
|
|
108
|
|
|
|
109
|
|
|
|
110
|
|
|
|
111
|
0
|
public GeneAnnotations( String filename, StatusViewer messenger )
|
|
112
|
|
throws IOException {
|
|
113
|
|
|
|
114
|
0
|
setUpDataStructures();
|
|
115
|
0
|
this.messenger = messenger;
|
|
116
|
|
|
|
117
|
0
|
this.read( filename );
|
|
118
|
|
|
|
119
|
0
|
setUp();
|
|
120
|
|
}
|
|
121
|
|
|
|
122
|
|
|
|
123
|
|
|
|
124
|
|
|
|
125
|
|
|
|
126
|
|
|
|
127
|
|
|
|
128
|
0
|
public GeneAnnotations( GeneAnnotations geneData, Set activeProbes ) {
|
|
129
|
|
|
|
130
|
|
|
|
131
|
|
|
|
132
|
|
|
|
133
|
0
|
probeToGeneSetMap = new LinkedHashMap( geneData.probeToGeneSetMap );
|
|
134
|
|
|
|
135
|
|
|
|
136
|
0
|
this.geneSetToProbeMap = new LinkedHashMap();
|
|
137
|
0
|
for ( Iterator iter = geneData.geneSetToProbeMap.keySet().iterator(); iter
|
|
138
|
|
.hasNext(); ) {
|
|
139
|
0
|
String key = ( String ) iter.next();
|
|
140
|
0
|
this.geneSetToProbeMap.put( key, new ArrayList(
|
|
141
|
|
( ArrayList ) geneData.geneSetToProbeMap.get( key ) ) );
|
|
142
|
|
}
|
|
143
|
|
|
|
144
|
0
|
probeToGeneName = new HashMap( geneData.probeToGeneName );
|
|
145
|
0
|
probeToDescription = new HashMap( geneData.probeToDescription );
|
|
146
|
0
|
geneToProbeList = new HashMap( geneData.geneToProbeList );
|
|
147
|
0
|
geneToGeneSetMap = new HashMap( geneData.geneToGeneSetMap );
|
|
148
|
0
|
geneSetToRedundantMap = new HashMap( geneData.geneSetToRedundantMap );
|
|
149
|
|
|
|
150
|
0
|
Vector allProbes = new Vector( probeToGeneName.keySet() );
|
|
151
|
0
|
for ( Iterator iter = allProbes.iterator(); iter.hasNext(); ) {
|
|
152
|
0
|
String probe = ( String ) iter.next();
|
|
153
|
0
|
if ( !activeProbes.contains( probe ) ) {
|
|
154
|
0
|
removeProbeFromMaps( probe );
|
|
155
|
|
}
|
|
156
|
|
}
|
|
157
|
0
|
setUp();
|
|
158
|
|
|
|
159
|
|
|
|
160
|
|
|
|
161
|
|
|
|
162
|
|
|
|
163
|
|
}
|
|
164
|
|
|
|
165
|
|
|
|
166
|
|
|
|
167
|
|
|
|
168
|
|
|
|
169
|
|
|
|
170
|
|
|
|
171
|
|
|
|
172
|
0
|
public GeneAnnotations( InputStream stream, Set activeGenes,
|
|
173
|
|
StatusViewer messenger ) throws IOException {
|
|
174
|
0
|
this.messenger = messenger;
|
|
175
|
0
|
setUpDataStructures();
|
|
176
|
0
|
this.read( stream, activeGenes );
|
|
177
|
0
|
setUp();
|
|
178
|
|
}
|
|
179
|
|
|
|
180
|
|
|
|
181
|
|
|
|
182
|
|
|
|
183
|
0
|
public GeneAnnotations( String fileName, Set activeGenes,
|
|
184
|
|
StatusViewer messenger ) throws IOException {
|
|
185
|
0
|
this.messenger = messenger;
|
|
186
|
0
|
FileInputStream fis = new FileInputStream( fileName );
|
|
187
|
0
|
BufferedInputStream bis = new BufferedInputStream( fis );
|
|
188
|
0
|
setUpDataStructures();
|
|
189
|
0
|
this.read( bis, activeGenes );
|
|
190
|
0
|
setUp();
|
|
191
|
|
}
|
|
192
|
|
|
|
193
|
|
|
|
194
|
|
|
|
195
|
|
|
|
196
|
0
|
public Map getProbeToGeneMap() {
|
|
197
|
0
|
return probeToGeneName;
|
|
198
|
|
}
|
|
199
|
|
|
|
200
|
|
|
|
201
|
|
|
|
202
|
|
|
|
203
|
0
|
public Map getGeneToProbeList() {
|
|
204
|
0
|
return geneToProbeList;
|
|
205
|
|
}
|
|
206
|
|
|
|
207
|
|
|
|
208
|
|
|
|
209
|
|
|
|
210
|
0
|
public Map getGeneSetToProbeMap() {
|
|
211
|
0
|
return geneSetToProbeMap;
|
|
212
|
|
}
|
|
213
|
|
|
|
214
|
|
|
|
215
|
|
|
|
216
|
|
|
|
217
|
|
|
|
218
|
0
|
public ArrayList getClassToProbes( String id ) {
|
|
219
|
0
|
return ( ArrayList ) geneSetToProbeMap.get( id );
|
|
220
|
|
}
|
|
221
|
|
|
|
222
|
|
|
|
223
|
|
|
|
224
|
|
|
|
225
|
|
|
|
226
|
0
|
public void sortGeneSets() {
|
|
227
|
|
|
|
228
|
0
|
if ( geneSetToProbeMap.size() == 0 ) {
|
|
229
|
0
|
throw new IllegalStateException(
|
|
230
|
|
"Could not sort because there are no gene sets in the classToProbeMap" );
|
|
231
|
|
}
|
|
232
|
|
|
|
233
|
0
|
if ( sortedGeneSets == null ) {
|
|
234
|
0
|
sortedGeneSets = new Vector();
|
|
235
|
|
}
|
|
236
|
|
|
|
237
|
0
|
Vector vec = new Vector( geneSetToProbeMap.keySet() );
|
|
238
|
0
|
Collections.sort( vec );
|
|
239
|
0
|
for ( Iterator iter = vec.iterator(); iter.hasNext(); ) {
|
|
240
|
0
|
sortedGeneSets.add( iter.next() );
|
|
241
|
|
}
|
|
242
|
|
}
|
|
243
|
|
|
|
244
|
|
|
|
245
|
|
|
|
246
|
|
|
|
247
|
0
|
public List sortGeneSetsBySize() {
|
|
248
|
|
|
|
249
|
0
|
List sets = new Vector();
|
|
250
|
0
|
for ( Iterator iter = getGeneSetToGeneMap().keySet().iterator(); iter
|
|
251
|
|
.hasNext(); ) {
|
|
252
|
0
|
String name = ( String ) iter.next();
|
|
253
|
0
|
sets.add( new GeneSet( name, ( Set ) geneSetToGeneMap.get( name ) ) );
|
|
254
|
|
}
|
|
255
|
|
|
|
256
|
0
|
Collections.sort( sets, new ClassSizeComparator() );
|
|
257
|
|
|
|
258
|
0
|
List returnVal = new Vector();
|
|
259
|
0
|
for ( Iterator iter = sets.iterator(); iter.hasNext(); ) {
|
|
260
|
0
|
returnVal.add( ( ( GeneSet ) iter.next() ).getName() );
|
|
261
|
|
}
|
|
262
|
|
|
|
263
|
0
|
return returnVal;
|
|
264
|
|
}
|
|
265
|
|
|
|
266
|
|
|
|
267
|
|
|
|
268
|
|
|
|
269
|
0
|
public Map getProbeToGeneSetMap() {
|
|
270
|
0
|
return probeToGeneSetMap;
|
|
271
|
|
}
|
|
272
|
|
|
|
273
|
|
|
|
274
|
|
|
|
275
|
|
|
|
276
|
0
|
public Map geneSetToRedundantMap() {
|
|
277
|
0
|
return geneSetToRedundantMap;
|
|
278
|
|
}
|
|
279
|
|
|
|
280
|
|
|
|
281
|
|
|
|
282
|
|
|
|
283
|
|
|
|
284
|
|
|
|
285
|
|
|
|
286
|
0
|
public String getProbeGeneName( String p ) {
|
|
287
|
0
|
return ( String ) probeToGeneName.get( p );
|
|
288
|
|
}
|
|
289
|
|
|
|
290
|
|
|
|
291
|
|
|
|
292
|
|
|
|
293
|
|
|
|
294
|
|
|
|
295
|
|
|
|
296
|
0
|
public String getProbeDescription( String p ) {
|
|
297
|
0
|
return ( String ) probeToDescription.get( p );
|
|
298
|
|
}
|
|
299
|
|
|
|
300
|
|
|
|
301
|
|
|
|
302
|
|
|
|
303
|
|
|
|
304
|
|
|
|
305
|
|
|
|
306
|
0
|
public ArrayList getGeneProbeList( String g ) {
|
|
307
|
0
|
return ( ArrayList ) geneToProbeList.get( g );
|
|
308
|
|
}
|
|
309
|
|
|
|
310
|
|
|
|
311
|
|
|
|
312
|
|
|
|
313
|
|
|
|
314
|
|
|
|
315
|
|
|
|
316
|
0
|
public String getGeneSetByIndex( int i ) {
|
|
317
|
0
|
return ( String ) sortedGeneSets.get( i );
|
|
318
|
|
}
|
|
319
|
|
|
|
320
|
|
|
|
321
|
|
|
|
322
|
|
|
|
323
|
|
|
|
324
|
|
|
|
325
|
|
|
|
326
|
0
|
public boolean geneSetExists( String id ) {
|
|
327
|
0
|
return geneSetToProbeMap.containsKey( id );
|
|
328
|
|
}
|
|
329
|
|
|
|
330
|
|
|
|
331
|
|
|
|
332
|
|
|
|
333
|
|
|
|
334
|
|
|
|
335
|
|
|
|
336
|
0
|
public int numProbesForGene( String g ) {
|
|
337
|
0
|
if ( !geneToProbeList.containsKey( g ) ) return 0;
|
|
338
|
0
|
return ( ( ArrayList ) geneToProbeList.get( g ) ).size();
|
|
339
|
|
}
|
|
340
|
|
|
|
341
|
|
|
|
342
|
|
|
|
343
|
|
|
|
344
|
|
|
|
345
|
|
|
|
346
|
0
|
public int numGeneSets() {
|
|
347
|
0
|
if ( geneSetToGeneMap == null ) {
|
|
348
|
0
|
throw new IllegalStateException( "classToGeneMap was null" );
|
|
349
|
|
}
|
|
350
|
0
|
return geneSetToGeneMap.size();
|
|
351
|
|
}
|
|
352
|
|
|
|
353
|
|
|
|
354
|
|
|
|
355
|
|
|
|
356
|
0
|
public int numGenes() {
|
|
357
|
0
|
return geneToProbeList.size();
|
|
358
|
|
}
|
|
359
|
|
|
|
360
|
|
|
|
361
|
|
|
|
362
|
|
|
|
363
|
|
|
|
364
|
|
|
|
365
|
|
|
|
366
|
0
|
public int numProbesInGeneSet( String id ) {
|
|
367
|
0
|
if ( !geneSetToProbeMap.containsKey( id ) ) {
|
|
368
|
0
|
return 0;
|
|
369
|
|
}
|
|
370
|
|
|
|
371
|
|
|
|
372
|
0
|
return ( ( ArrayList ) geneSetToProbeMap.get( id ) ).size();
|
|
373
|
|
}
|
|
374
|
|
|
|
375
|
|
|
|
376
|
|
|
|
377
|
|
|
|
378
|
|
|
|
379
|
|
|
|
380
|
|
|
|
381
|
0
|
public int numGenesInGeneSet( String id ) {
|
|
382
|
0
|
if ( !geneSetToGeneMap.containsKey( id ) ) {
|
|
383
|
0
|
return 0;
|
|
384
|
|
}
|
|
385
|
0
|
return ( ( Set ) geneSetToGeneMap.get( id ) ).size();
|
|
386
|
|
}
|
|
387
|
|
|
|
388
|
|
|
|
389
|
|
|
|
390
|
|
|
|
391
|
|
|
|
392
|
|
|
|
393
|
|
|
|
394
|
0
|
public void addClass( String id, ArrayList probesForNew ) {
|
|
395
|
0
|
geneSetToProbeMap.put( id, probesForNew );
|
|
396
|
|
|
|
397
|
0
|
Iterator probe_it = probesForNew.iterator();
|
|
398
|
0
|
while ( probe_it.hasNext() ) {
|
|
399
|
0
|
String probe = new String( ( String ) probe_it.next() );
|
|
400
|
0
|
( ( ArrayList ) probeToGeneSetMap.get( probe ) ).add( id );
|
|
401
|
|
}
|
|
402
|
|
|
|
403
|
0
|
Set genes = new HashSet();
|
|
404
|
0
|
Iterator probe_it2 = probesForNew.iterator();
|
|
405
|
0
|
while ( probe_it2.hasNext() ) {
|
|
406
|
0
|
genes.add( probeToGeneName.get( probe_it2.next() ) );
|
|
407
|
|
}
|
|
408
|
0
|
geneSetToGeneMap.put( id, genes );
|
|
409
|
|
|
|
410
|
0
|
geneToGeneSetMap.put( id, probeToGeneSetMap.get( id ) );
|
|
411
|
|
|
|
412
|
0
|
resetSelectedSets();
|
|
413
|
|
}
|
|
414
|
|
|
|
415
|
|
|
|
416
|
|
|
|
417
|
|
|
|
418
|
|
|
|
419
|
|
|
|
420
|
|
|
|
421
|
|
|
|
422
|
0
|
public void modifyClass( String classId, ArrayList probesForNew ) {
|
|
423
|
0
|
ArrayList orig_probes = ( ArrayList ) geneSetToProbeMap.get( classId );
|
|
424
|
0
|
Iterator orig_probe_it = orig_probes.iterator();
|
|
425
|
0
|
while ( orig_probe_it.hasNext() ) {
|
|
426
|
0
|
String orig_probe = new String( ( String ) orig_probe_it.next() );
|
|
427
|
0
|
if ( !probesForNew.contains( orig_probe ) ) {
|
|
428
|
0
|
Set ptc = new HashSet( ( Collection ) probeToGeneSetMap
|
|
429
|
|
.get( orig_probe ) );
|
|
430
|
0
|
ptc.remove( classId );
|
|
431
|
0
|
probeToGeneSetMap.remove( orig_probe );
|
|
432
|
0
|
probeToGeneSetMap.put( orig_probe, new ArrayList( ptc ) );
|
|
433
|
|
}
|
|
434
|
|
}
|
|
435
|
0
|
Iterator probe_it = probesForNew.iterator();
|
|
436
|
0
|
while ( probe_it.hasNext() ) {
|
|
437
|
0
|
String probe = ( String ) probe_it.next();
|
|
438
|
0
|
if ( !orig_probes.contains( probe ) ) {
|
|
439
|
0
|
( ( ArrayList ) probeToGeneSetMap.get( probe ) ).add( classId );
|
|
440
|
|
}
|
|
441
|
|
}
|
|
442
|
0
|
geneSetToProbeMap.put( classId, probesForNew );
|
|
443
|
0
|
resetSelectedSets();
|
|
444
|
|
}
|
|
445
|
|
|
|
446
|
|
|
|
447
|
|
|
|
448
|
|
|
|
449
|
0
|
public TableModel toTableModel() {
|
|
450
|
0
|
return new AbstractTableModel() {
|
|
451
|
|
private String[] columnNames = {
|
|
452
|
|
"Probe", "Gene", "Description"
|
|
453
|
|
};
|
|
454
|
|
|
|
455
|
0
|
public String getColumnName( int i ) {
|
|
456
|
0
|
return columnNames[i];
|
|
457
|
|
}
|
|
458
|
|
|
|
459
|
0
|
public int getColumnCount() {
|
|
460
|
0
|
return 3;
|
|
461
|
|
}
|
|
462
|
|
|
|
463
|
0
|
public int getRowCount() {
|
|
464
|
0
|
return selectedProbes.size();
|
|
465
|
|
}
|
|
466
|
|
|
|
467
|
0
|
public Object getValueAt( int i, int j ) {
|
|
468
|
|
|
|
469
|
0
|
String probeid = ( String ) selectedProbes.get( i );
|
|
470
|
0
|
switch ( j ) {
|
|
471
|
|
case 0:
|
|
472
|
0
|
return probeid;
|
|
473
|
|
case 1:
|
|
474
|
0
|
return getProbeGeneName( probeid );
|
|
475
|
|
case 2:
|
|
476
|
0
|
return getProbeDescription( probeid );
|
|
477
|
|
default:
|
|
478
|
0
|
return null;
|
|
479
|
|
}
|
|
480
|
|
}
|
|
481
|
|
|
|
482
|
|
};
|
|
483
|
|
}
|
|
484
|
|
|
|
485
|
|
|
|
486
|
|
|
|
487
|
|
|
|
488
|
|
|
|
489
|
|
|
|
490
|
0
|
public void selectProbes( String searchOn ) {
|
|
491
|
|
|
|
492
|
0
|
String searchOnUp = searchOn.toUpperCase();
|
|
493
|
0
|
resetSelectedProbes();
|
|
494
|
0
|
Set removeUs = new HashSet();
|
|
495
|
0
|
for ( Iterator it = probeToGeneName.keySet().iterator(); it.hasNext(); ) {
|
|
496
|
0
|
String probe = ( String ) it.next();
|
|
497
|
|
|
|
498
|
0
|
String candidate = ( ( String ) probeToGeneName.get( ( probe ) ) )
|
|
499
|
|
.toUpperCase();
|
|
500
|
|
|
|
501
|
|
|
|
502
|
0
|
String candidateD = ( ( String ) probeToDescription.get( ( probe ) ) )
|
|
503
|
|
.toUpperCase();
|
|
504
|
|
|
|
505
|
0
|
if ( !candidate.startsWith( searchOnUp )
|
|
506
|
|
&& candidateD.indexOf( searchOnUp ) < 0 ) {
|
|
507
|
0
|
removeUs.add( probe );
|
|
508
|
|
}
|
|
509
|
|
|
|
510
|
|
}
|
|
511
|
|
|
|
512
|
0
|
for ( Iterator it = removeUs.iterator(); it.hasNext(); ) {
|
|
513
|
0
|
selectedProbes.remove( it.next() );
|
|
514
|
|
}
|
|
515
|
|
}
|
|
516
|
|
|
|
517
|
|
|
|
518
|
|
|
|
519
|
|
|
|
520
|
0
|
public void resetSelectedProbes() {
|
|
521
|
0
|
selectedProbes = new Vector( probeToGeneName.keySet() );
|
|
522
|
|
}
|
|
523
|
|
|
|
524
|
|
|
|
525
|
|
|
|
526
|
|
|
|
527
|
0
|
public List getSelectedProbes() {
|
|
528
|
0
|
return selectedProbes;
|
|
529
|
|
}
|
|
530
|
|
|
|
531
|
|
|
|
532
|
|
|
|
533
|
|
|
|
534
|
0
|
public int selectedProbes() {
|
|
535
|
0
|
return selectedProbes.size();
|
|
536
|
|
}
|
|
537
|
|
|
|
538
|
|
|
|
539
|
|
|
|
540
|
|
|
|
541
|
|
|
|
542
|
0
|
public void selectSets( String searchOn, GONames goData ) {
|
|
543
|
|
|
|
544
|
0
|
String searchOnUp = searchOn.toUpperCase();
|
|
545
|
0
|
resetSelectedSets();
|
|
546
|
0
|
Set removeUs = new HashSet();
|
|
547
|
0
|
for ( Iterator it = geneSetToProbeMap.keySet().iterator(); it.hasNext(); ) {
|
|
548
|
0
|
String candidate = ( String ) it.next();
|
|
549
|
|
|
|
550
|
|
|
|
551
|
0
|
String candidateN = goData.getNameForId( candidate ).toUpperCase();
|
|
552
|
|
|
|
553
|
0
|
if ( !candidate.toUpperCase().startsWith( searchOnUp )
|
|
554
|
|
&& candidateN.indexOf( searchOnUp ) < 0 ) {
|
|
555
|
0
|
removeUs.add( candidate );
|
|
556
|
|
}
|
|
557
|
|
}
|
|
558
|
|
|
|
559
|
0
|
for ( Iterator it = removeUs.iterator(); it.hasNext(); ) {
|
|
560
|
0
|
selectedSets.remove( it.next() );
|
|
561
|
|
}
|
|
562
|
|
}
|
|
563
|
|
|
|
564
|
|
|
|
565
|
|
|
|
566
|
|
|
|
567
|
0
|
public void resetSelectedSets() {
|
|
568
|
0
|
selectedSets = new Vector( geneSetToProbeMap.keySet() );
|
|
569
|
|
}
|
|
570
|
|
|
|
571
|
|
|
|
572
|
|
|
|
573
|
|
|
|
574
|
0
|
public List getSelectedSets() {
|
|
575
|
0
|
return selectedSets;
|
|
576
|
|
}
|
|
577
|
|
|
|
578
|
|
|
|
579
|
|
|
|
580
|
|
|
|
581
|
0
|
public int selectedSets() {
|
|
582
|
0
|
return selectedSets.size();
|
|
583
|
|
}
|
|
584
|
|
|
|
585
|
|
|
|
586
|
|
|
|
587
|
|
|
|
588
|
|
|
|
589
|
|
|
|
590
|
|
|
|
591
|
|
|
|
592
|
0
|
public void print( Writer out ) throws IOException {
|
|
593
|
0
|
out.write( "Probe\tSymbol\tName\tGeneSets\n" );
|
|
594
|
0
|
out.flush();
|
|
595
|
0
|
for ( Iterator iter = probeToGeneName.keySet().iterator(); iter.hasNext(); ) {
|
|
596
|
0
|
String probe = ( String ) iter.next();
|
|
597
|
0
|
String gene = ( String ) probeToGeneName.get( probe );
|
|
598
|
0
|
String desc = getProbeDescription( probe );
|
|
599
|
0
|
out.write( probe + "\t" + gene + "\t" + desc + "\t" );
|
|
600
|
0
|
List geneSets = ( ArrayList ) probeToGeneSetMap.get( probe );
|
|
601
|
|
|
|
602
|
0
|
for ( Iterator iterator = geneSets.iterator(); iterator.hasNext(); ) {
|
|
603
|
0
|
String element = ( String ) iterator.next();
|
|
604
|
0
|
out.write( element + "|" );
|
|
605
|
|
}
|
|
606
|
0
|
out.write( "\n" );
|
|
607
|
|
}
|
|
608
|
|
}
|
|
609
|
|
|
|
610
|
|
|
|
611
|
|
|
|
612
|
|
|
|
613
|
0
|
public Map getGeneSetToGeneMap() {
|
|
614
|
0
|
return geneSetToGeneMap;
|
|
615
|
|
}
|
|
616
|
|
|
|
617
|
|
|
|
618
|
|
|
|
619
|
|
|
|
620
|
0
|
public Map getGeneToGeneSetMap() {
|
|
621
|
0
|
return geneToGeneSetMap;
|
|
622
|
|
}
|
|
623
|
|
|
|
624
|
|
|
|
625
|
|
|
|
626
|
|
|
|
627
|
|
|
|
628
|
|
|
|
629
|
0
|
public int numAnnotatedGenes() {
|
|
630
|
0
|
int count = 0;
|
|
631
|
0
|
for ( Iterator iter = probeToGeneSetMap.keySet().iterator(); iter
|
|
632
|
|
.hasNext(); ) {
|
|
633
|
0
|
List element = ( ArrayList ) probeToGeneSetMap.get( iter.next() );
|
|
634
|
0
|
if ( element.size() > 0 ) {
|
|
635
|
0
|
count++;
|
|
636
|
|
}
|
|
637
|
|
}
|
|
638
|
0
|
return count;
|
|
639
|
|
}
|
|
640
|
|
|
|
641
|
|
|
|
642
|
|
|
|
643
|
|
|
|
644
|
|
|
|
645
|
|
|
|
646
|
|
|
|
647
|
|
|
|
648
|
0
|
private void setUpDataStructures() {
|
|
649
|
0
|
probeToGeneSetMap = new LinkedHashMap();
|
|
650
|
0
|
geneSetToProbeMap = new LinkedHashMap();
|
|
651
|
0
|
probeToGeneName = new HashMap();
|
|
652
|
0
|
probeToDescription = new HashMap();
|
|
653
|
0
|
geneToProbeList = new HashMap();
|
|
654
|
0
|
geneToGeneSetMap = new HashMap();
|
|
655
|
0
|
geneSetToRedundantMap = new HashMap();
|
|
656
|
|
}
|
|
657
|
|
|
|
658
|
|
|
|
659
|
|
|
|
660
|
|
|
|
661
|
0
|
private void setUp() {
|
|
662
|
0
|
this.geneSetToGeneMap = makeClassToGeneMap();
|
|
663
|
|
|
|
664
|
0
|
GeneSetMapTools.collapseGeneSets( this, messenger );
|
|
665
|
0
|
prune( ABSOLUTE_MINIMUM_GENESET_SIZE, PRACTICAL_MAXIMUM_GENESET_SIZE );
|
|
666
|
0
|
resetSelectedProbes();
|
|
667
|
0
|
resetSelectedSets();
|
|
668
|
0
|
sortGeneSets();
|
|
669
|
|
}
|
|
670
|
|
|
|
671
|
|
|
|
672
|
|
|
|
673
|
|
|
|
674
|
|
|
|
675
|
|
|
|
676
|
0
|
public void removeClassFromMaps( String id ) {
|
|
677
|
0
|
if ( geneSetToProbeMap.containsKey( id ) ) {
|
|
678
|
0
|
for ( Iterator pit = ( ( ArrayList ) geneSetToProbeMap.get( id ) )
|
|
679
|
0
|
.iterator(); pit.hasNext(); ) {
|
|
680
|
0
|
String probe = ( String ) pit.next();
|
|
681
|
0
|
if ( probeToGeneSetMap.containsKey( probe )
|
|
682
|
|
&& ( ( ArrayList ) probeToGeneSetMap.get( probe ) )
|
|
683
|
|
.contains( id ) ) {
|
|
684
|
0
|
if ( !( ( ArrayList ) probeToGeneSetMap.get( probe ) )
|
|
685
|
|
.remove( id ) ) {
|
|
686
|
0
|
System.err.println( "Couldn't remove " + id
|
|
687
|
|
+ " from probe to class map for" + probe );
|
|
688
|
|
}
|
|
689
|
|
}
|
|
690
|
|
}
|
|
691
|
0
|
if ( geneSetToProbeMap.remove( id ) == null )
|
|
692
|
0
|
System.err.println( "Couldn't remove " + id
|
|
693
|
|
+ " from classToProbeMap" );
|
|
694
|
|
|
|
695
|
0
|
if ( geneSetToGeneMap.remove( id ) == null )
|
|
696
|
0
|
System.err.println( "Couldn't remove " + id
|
|
697
|
|
+ " from classToGeneMap" );
|
|
698
|
|
}
|
|
699
|
0
|
if ( geneSetToRedundantMap.containsKey( id ) )
|
|
700
|
0
|
geneSetToRedundantMap.remove( id );
|
|
701
|
|
}
|
|
702
|
|
|
|
703
|
|
|
|
704
|
|
|
|
705
|
|
|
|
706
|
0
|
private void removeProbeFromMaps( String probe ) {
|
|
707
|
0
|
if ( probeToGeneName.containsKey( probe ) ) {
|
|
708
|
0
|
String gene = ( String ) probeToGeneName.get( probe );
|
|
709
|
0
|
probeToGeneName.remove( probe );
|
|
710
|
0
|
if ( geneToProbeList.containsKey( gene ) ) {
|
|
711
|
0
|
( ( ArrayList ) geneToProbeList.get( gene ) ).remove( probe );
|
|
712
|
|
}
|
|
713
|
|
}
|
|
714
|
0
|
if ( probeToGeneSetMap.containsKey( probe ) ) {
|
|
715
|
0
|
Iterator cit = ( ( ArrayList ) probeToGeneSetMap.get( probe ) )
|
|
716
|
|
.iterator();
|
|
717
|
0
|
while ( cit.hasNext() ) {
|
|
718
|
0
|
String geneSet = ( String ) cit.next();
|
|
719
|
0
|
if ( geneSetToProbeMap.containsKey( geneSet ) ) {
|
|
720
|
0
|
( ( ArrayList ) geneSetToProbeMap.get( geneSet ) )
|
|
721
|
|
.remove( probe );
|
|
722
|
|
}
|
|
723
|
|
}
|
|
724
|
0
|
if ( probeToGeneSetMap.remove( probe ) == null ) {
|
|
725
|
0
|
System.err.println( "Could not remove " + probe
|
|
726
|
|
+ " from probeToClassMap" );
|
|
727
|
|
}
|
|
728
|
|
}
|
|
729
|
0
|
if ( probeToDescription.containsKey( probe ) )
|
|
730
|
0
|
probeToDescription.remove( probe );
|
|
731
|
|
}
|
|
732
|
|
|
|
733
|
|
|
|
734
|
|
|
|
735
|
|
|
|
736
|
|
|
|
737
|
|
|
|
738
|
0
|
private Map makeClassToGeneMap() {
|
|
739
|
0
|
Map gsToGeneMap = new HashMap();
|
|
740
|
0
|
for ( Iterator iter = geneSetToProbeMap.keySet().iterator(); iter
|
|
741
|
|
.hasNext(); ) {
|
|
742
|
0
|
String geneSetId = ( String ) iter.next();
|
|
743
|
0
|
List probesInSet = ( ArrayList ) geneSetToProbeMap.get( geneSetId );
|
|
744
|
|
|
|
745
|
0
|
Set genesInSet = new HashSet();
|
|
746
|
0
|
for ( Iterator biter = probesInSet.iterator(); biter.hasNext(); ) {
|
|
747
|
0
|
String probe = ( String ) biter.next();
|
|
748
|
0
|
genesInSet.add( probeToGeneName.get( probe ) );
|
|
749
|
|
}
|
|
750
|
0
|
gsToGeneMap.put( geneSetId, genesInSet );
|
|
751
|
|
}
|
|
752
|
0
|
return gsToGeneMap;
|
|
753
|
|
}
|
|
754
|
|
|
|
755
|
0
|
private void read( InputStream bis ) throws IOException {
|
|
756
|
0
|
this.read( bis, null );
|
|
757
|
|
}
|
|
758
|
|
|
|
759
|
0
|
private void read( InputStream bis, Set activeGenes ) throws IOException {
|
|
760
|
0
|
if ( bis == null ) {
|
|
761
|
0
|
throw new IOException( "Inputstream was null" );
|
|
762
|
|
}
|
|
763
|
|
|
|
764
|
0
|
BufferedReader dis = new BufferedReader( new InputStreamReader( bis ) );
|
|
765
|
0
|
ArrayList probeIds = new ArrayList();
|
|
766
|
0
|
String classIds = null;
|
|
767
|
|
|
|
768
|
|
|
|
769
|
|
|
|
770
|
0
|
int n = 0;
|
|
771
|
0
|
String line = "";
|
|
772
|
|
|
|
773
|
0
|
while ( ( line = dis.readLine() ) != null ) {
|
|
774
|
0
|
if ( line.startsWith( "#" ) ) continue;
|
|
775
|
0
|
StringTokenizer st = new StringTokenizer( line, "\t" );
|
|
776
|
|
|
|
777
|
0
|
if ( !st.hasMoreTokens() ) {
|
|
778
|
0
|
continue;
|
|
779
|
|
}
|
|
780
|
|
|
|
781
|
0
|
String probe = st.nextToken().intern();
|
|
782
|
|
|
|
783
|
|
|
|
784
|
0
|
if ( !st.hasMoreTokens() ) {
|
|
785
|
0
|
continue;
|
|
786
|
|
}
|
|
787
|
|
|
|
788
|
0
|
String group = st.nextToken().intern();
|
|
789
|
|
|
|
790
|
0
|
if ( activeGenes != null && !activeGenes.contains( group ) ) {
|
|
791
|
0
|
continue;
|
|
792
|
|
}
|
|
793
|
|
|
|
794
|
0
|
probeToGeneName.put( probe.intern(), group.intern() );
|
|
795
|
|
|
|
796
|
|
|
|
797
|
0
|
if ( geneToProbeList.get( group ) == null ) {
|
|
798
|
0
|
geneToProbeList.put( group.intern(), new ArrayList() );
|
|
799
|
|
}
|
|
800
|
0
|
( ( ArrayList ) geneToProbeList.get( group ) ).add( probe.intern() );
|
|
801
|
|
|
|
802
|
0
|
probeIds.add( probe );
|
|
803
|
0
|
probeToGeneSetMap.put( probe.intern(), new ArrayList() );
|
|
804
|
0
|
geneToGeneSetMap.put( group, probeToGeneSetMap.get( probe ) );
|
|
805
|
|
|
|
806
|
|
|
|
807
|
0
|
if ( st.hasMoreTokens() ) {
|
|
808
|
0
|
String description = st.nextToken().intern();
|
|
809
|
0
|
if ( !description.startsWith( "GO:" ) ) {
|
|
810
|
|
|
|
811
|
|
|
|
812
|
|
|
|
813
|
|
|
|
814
|
0
|
probeToDescription.put( probe.intern(), description.intern() );
|
|
815
|
|
} else {
|
|
816
|
0
|
probeToDescription.put( probe.intern(), "[No description]" );
|
|
817
|
|
}
|
|
818
|
|
} else {
|
|
819
|
0
|
probeToDescription.put( probe.intern(), "[No description]" );
|
|
820
|
|
}
|
|
821
|
|
|
|
822
|
|
|
|
823
|
0
|
if ( st.hasMoreTokens() ) {
|
|
824
|
0
|
classIds = st.nextToken();
|
|
825
|
|
|
|
826
|
|
|
|
827
|
|
|
|
828
|
0
|
StringTokenizer st1 = new StringTokenizer( classIds, "|" );
|
|
829
|
0
|
while ( st1.hasMoreTokens() ) {
|
|
830
|
0
|
String go = st1.nextToken().intern();
|
|
831
|
|
|
|
832
|
|
|
|
833
|
0
|
( ( ArrayList ) probeToGeneSetMap.get( probe ) ).add( go );
|
|
834
|
|
|
|
835
|
|
|
|
836
|
0
|
if ( !geneSetToProbeMap.containsKey( go ) ) {
|
|
837
|
0
|
geneSetToProbeMap.put( go, new ArrayList() );
|
|
838
|
|
}
|
|
839
|
0
|
( ( ArrayList ) geneSetToProbeMap.get( go ) ).add( probe );
|
|
840
|
|
|
|
841
|
|
}
|
|
842
|
|
}
|
|
843
|
0
|
if ( messenger != null && n % 500 == 0 ) {
|
|
844
|
0
|
messenger.setStatus( "Read " + n + " probes" );
|
|
845
|
|
}
|
|
846
|
0
|
n++;
|
|
847
|
|
}
|
|
848
|
|
|
|
849
|
|
|
|
850
|
0
|
dis.close();
|
|
851
|
0
|
resetSelectedProbes();
|
|
852
|
|
|
|
853
|
0
|
if (probeToGeneName.size() == 0 || geneSetToProbeMap.size() == 0) {
|
|
854
|
0
|
throw new IllegalArgumentException("The gene annotations had invalid information. Please check the format.");
|
|
855
|
|
}
|
|
856
|
|
|
|
857
|
|
}
|
|
858
|
|
|
|
859
|
|
|
|
860
|
0
|
private void read( String filename ) throws IOException {
|
|
861
|
|
|
|
862
|
0
|
if ( !FileTools.testFile( filename ) ) {
|
|
863
|
0
|
throw new IOException( "Could not read from " + filename );
|
|
864
|
|
}
|
|
865
|
|
|
|
866
|
0
|
FileInputStream fis = new FileInputStream( filename );
|
|
867
|
0
|
BufferedInputStream bis = new BufferedInputStream( fis );
|
|
868
|
0
|
read( bis );
|
|
869
|
|
}
|
|
870
|
|
|
|
871
|
|
|
|
872
|
|
|
|
873
|
|
|
|
874
|
|
|
|
875
|
|
|
|
876
|
|
|
|
877
|
|
|
|
878
|
0
|
private void prune( int lowThreshold, int highThreshold ) {
|
|
879
|
|
|
|
880
|
0
|
Set removeUs = new HashSet();
|
|
881
|
0
|
for ( Iterator it = geneSetToProbeMap.keySet().iterator(); it.hasNext(); ) {
|
|
882
|
0
|
String id = ( String ) it.next();
|
|
883
|
0
|
if ( numProbesInGeneSet( id ) < lowThreshold
|
|
884
|
|
|| numGenesInGeneSet( id ) < lowThreshold
|
|
885
|
|
|| numProbesInGeneSet( id ) > highThreshold
|
|
886
|
|
|| numGenesInGeneSet( id ) > highThreshold ) {
|
|
887
|
0
|
removeUs.add( id );
|
|
888
|
|
}
|
|
889
|
|
}
|
|
890
|
|
|
|
891
|
0
|
for ( Iterator it = removeUs.iterator(); it.hasNext(); ) {
|
|
892
|
0
|
String id = ( String ) it.next();
|
|
893
|
0
|
removeClassFromMaps( id );
|
|
894
|
|
}
|
|
895
|
|
|
|
896
|
0
|
sortGeneSets();
|
|
897
|
|
}
|
|
898
|
|
|
|
899
|
|
}
|
|
900
|
|
|
|
901
|
|
class ClassSizeComparator implements Comparator {
|
|
902
|
|
|
|
903
|
|
|
|
904
|
|
|
|
905
|
|
|
|
906
|
|
|
|
907
|
|
|
|
908
|
0
|
public int compare( Object o1, Object o2 ) {
|
|
909
|
0
|
GeneSet a = ( GeneSet ) o1;
|
|
910
|
0
|
GeneSet b = ( GeneSet ) o2;
|
|
911
|
|
|
|
912
|
0
|
int sizea = a.size();
|
|
913
|
0
|
int sizeb = b.size();
|
|
914
|
|
|
|
915
|
0
|
if ( sizea > sizeb ) {
|
|
916
|
0
|
return 1;
|
|
917
|
0
|
} else if ( sizeb < sizea ) {
|
|
918
|
0
|
return -1;
|
|
919
|
|
}
|
|
920
|
|
|
|
921
|
0
|
return 0;
|
|
922
|
|
}
|
|
923
|
|
|
|
924
|
0
|
public static void main( String[] args ) {
|
|
925
|
|
}
|
|
926
|
|
}
|
|
927
|
|
|
|
928
|
|
|
|
929
|
|
|
|
930
|
|
class GeneSet {
|
|
931
|
|
private String name;
|
|
932
|
|
private Set items;
|
|
933
|
|
|
|
934
|
0
|
public GeneSet( String name, Set items ) {
|
|
935
|
0
|
this.name = name;
|
|
936
|
0
|
this.items = items;
|
|
937
|
|
}
|
|
938
|
|
|
|
939
|
|
|
|
940
|
|
|
|
941
|
|
|
|
942
|
0
|
public Set getItems() {
|
|
943
|
0
|
return items;
|
|
944
|
|
}
|
|
945
|
|
|
|
946
|
|
|
|
947
|
|
|
|
948
|
|
|
|
949
|
0
|
public void setItems( Set items ) {
|
|
950
|
0
|
this.items = items;
|
|
951
|
|
}
|
|
952
|
|
|
|
953
|
|
|
|
954
|
|
|
|
955
|
|
|
|
956
|
0
|
public String getName() {
|
|
957
|
0
|
return name;
|
|
958
|
|
}
|
|
959
|
|
|
|
960
|
|
|
|
961
|
|
|
|
962
|
|
|
|
963
|
0
|
public void setName( String name ) {
|
|
964
|
0
|
this.name = name;
|
|
965
|
|
}
|
|
966
|
|
|
|
967
|
0
|
public int size() {
|
|
968
|
0
|
return items.size();
|
|
969
|
|
}
|
|
970
|
|
}
|