13
13
14
14
import org .baderlab .csplugins .enrichmentmap .CyActivator ;
15
15
import org .baderlab .csplugins .enrichmentmap .model .DataSetFiles ;
16
+ import org .baderlab .csplugins .enrichmentmap .model .EMCreationParameters ;
16
17
import org .baderlab .csplugins .enrichmentmap .model .EMDataSet ;
17
18
import org .baderlab .csplugins .enrichmentmap .model .EMDataSet .Method ;
18
19
import org .baderlab .csplugins .enrichmentmap .model .EMSignatureDataSet ;
28
29
import org .baderlab .csplugins .enrichmentmap .model .SetOfGeneSets ;
29
30
import org .baderlab .csplugins .enrichmentmap .parsers .ExpressionFileReaderTask ;
30
31
import org .baderlab .csplugins .enrichmentmap .task .InitializeGenesetsOfInterestTask ;
31
- import org .baderlab .csplugins .enrichmentmap .util .NamingUtil ;
32
32
import org .cytoscape .application .CyApplicationManager ;
33
33
import org .cytoscape .io .util .StreamUtil ;
34
+ import org .cytoscape .model .CyEdge ;
34
35
import org .cytoscape .model .CyNetwork ;
35
36
import org .cytoscape .model .CyNetworkManager ;
37
+ import org .cytoscape .model .CyNode ;
38
+ import org .cytoscape .model .CyRow ;
36
39
import org .cytoscape .service .util .CyServiceRegistrar ;
37
40
import org .cytoscape .session .CySession ;
38
41
39
42
import com .google .inject .Inject ;
40
43
41
44
public class LegacySessionLoader {
42
45
46
+ private static final String SIG_DATA_SET_NAME = "Signature Gene Sets" ;
47
+
43
48
@ Inject private CyServiceRegistrar serviceRegistrar ;
44
49
@ Inject private CyNetworkManager cyNetworkManager ;
45
50
@ Inject private CyApplicationManager cyApplicationManager ;
@@ -60,13 +65,76 @@ public static boolean isLegacy(CySession session) {
60
65
return true ;
61
66
}
62
67
68
+
69
+ public void loadSession (CySession session ) {
70
+ createModelFromSessionFiles (session );
71
+ migrate ();
72
+ }
73
+
74
+
63
75
/**
64
- * Restore Enrichment maps
65
- *
66
- * @param pStateFileList - list of files associated with thie session
76
+ * Reconstruct important model data using EM2 conventions.
67
77
*/
78
+ private void migrate () {
79
+ for (EnrichmentMap map : emManager .getAllEnrichmentMaps ().values ()) {
80
+ if (map .isLegacy ()) { // Is this check necessary?
81
+ EMDataSet ds1 = map .getDataSet (LegacySupport .DATASET1 );
82
+ EMDataSet ds2 = map .getDataSet (LegacySupport .DATASET2 );
83
+ EMSignatureDataSet dsSig = map .getSignatureDataSet (SIG_DATA_SET_NAME );
84
+
85
+ EMCreationParameters params = map .getParams ();
86
+ String prefix = params .getAttributePrefix ();
87
+
88
+ // Restore column names for filtering
89
+ params .addPValueColumnName (prefix + "pvalue_dataset1" );
90
+ params .addQValueColumnName (prefix + "fdr_qvalue_dataset1" );
91
+ params .addSimilarityCutoffColumnName (prefix + "similarity_coefficient" );
92
+ if (ds2 != null ) {
93
+ params .addPValueColumnName (prefix + "pvalue_dataset2" );
94
+ params .addQValueColumnName (prefix + "fdr_qvalue_dataset2" );
95
+ }
96
+
97
+ // Restore node SUIDs
98
+ CyNetwork network = cyNetworkManager .getNetwork (map .getNetworkID ());
99
+ for (CyNode node : network .getNodeList ()) {
100
+ CyRow row = network .getRow (node );
101
+ if (ds1 != null ) {
102
+ Integer gsSize = row .get (prefix + "gs_size_dataset1" , Integer .class );
103
+ if (gsSize != null && gsSize > 0 )
104
+ ds1 .addNodeSuid (node .getSUID ());
105
+ }
106
+ if (ds2 != null ) {
107
+ Integer gsSize = row .get (prefix + "gs_size_dataset2" , Integer .class );
108
+ if (gsSize != null && gsSize > 0 )
109
+ ds2 .addNodeSuid (node .getSUID ());
110
+ }
111
+ if (dsSig != null ) {
112
+ Integer gsSize = row .get (prefix + "gs_size_signature" , Integer .class );
113
+ if (gsSize != null && gsSize > 0 )
114
+ dsSig .addNodeSuid (node .getSUID ());
115
+ }
116
+ }
117
+
118
+ // Restore edge SUIDs
119
+ for (CyEdge edge : network .getEdgeList ()) {
120
+ CyRow row = network .getRow (edge );
121
+ Integer emSet = row .get (prefix + "ENRICHMENT_SET" , Integer .class );
122
+ if (emSet != null ) {
123
+ if (emSet == 0 || emSet == 1 )
124
+ ds1 .addEdgeSuid (edge .getSUID ());
125
+ else if (emSet == 2 )
126
+ ds2 .addEdgeSuid (edge .getSUID ());
127
+ else if (emSet == 4 )
128
+ dsSig .addEdgeSuid (edge .getSUID ());
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
134
+
135
+
68
136
@ SuppressWarnings ("unchecked" )
69
- public void loadSession (CySession session ) {
137
+ private void createModelFromSessionFiles (CySession session ) {
70
138
Map <Long , EnrichmentMapParameters > paramsMap = new HashMap <>();
71
139
Map <Long , EnrichmentMap > enrichmentMapMap = new HashMap <>();
72
140
@@ -80,8 +148,9 @@ public void loadSession(CySession session) {
80
148
String fullText = new Scanner (reader , "UTF-8" ).useDelimiter ("\\ A" ).next ();
81
149
82
150
//Given the file with all the parameters create a new parameter
83
- EnrichmentMapParameters params = enrichmentMapParametersFactory .create (fullText );
84
- EnrichmentMap em = new EnrichmentMap (params .getCreationParameters (), serviceRegistrar );
151
+ EnrichmentMapParameters legacyParams = enrichmentMapParametersFactory .create (fullText );
152
+ EMCreationParameters newParams = legacyParams .getCreationParameters ();
153
+ EnrichmentMap em = new EnrichmentMap (newParams , serviceRegistrar );
85
154
86
155
//get the network name
87
156
String param_name = em .getName ();
@@ -99,18 +168,18 @@ public void loadSession(CySession session) {
99
168
100
169
//after associated the properties with the network
101
170
//initialized each Dataset that we have files for
102
- HashMap <String , DataSetFiles > files = params .getFiles ();
171
+ HashMap <String , DataSetFiles > files = legacyParams .getFiles ();
103
172
104
- for (Iterator <String > j = params .getFiles ().keySet ().iterator (); j .hasNext ();) {
173
+ for (Iterator <String > j = legacyParams .getFiles ().keySet ().iterator (); j .hasNext ();) {
105
174
String current_dataset = j .next ();
106
- Method method = EnrichmentMapParameters .stringToMethod (params .getMethod ());
175
+ Method method = EnrichmentMapParameters .stringToMethod (legacyParams .getMethod ());
107
176
em .createDataSet (current_dataset , method , files .get (current_dataset ));
108
177
}
109
178
110
179
CyNetwork network = getNetworkByName (networkName );
111
180
Long suid = network .getSUID ();
112
181
em .setNetworkID (suid );
113
- paramsMap .put (suid , params );
182
+ paramsMap .put (suid , legacyParams );
114
183
enrichmentMapMap .put (suid , em );
115
184
}
116
185
}
@@ -151,9 +220,9 @@ public void loadSession(CySession session) {
151
220
152
221
if (propFile .getName ().contains (".signature.gmt" )) {
153
222
// TODO Find a better way to serialize EMSignatureDataSet
154
- String sdsName = propFile .getName ().replace (".signature.gmt" , "" );
155
- sdsName = NamingUtil .getUniqueName (sdsName , em .getSignatureDataSets ().keySet ());
156
- EMSignatureDataSet sigDataSet = new EMSignatureDataSet (sdsName );
223
+ // String sdsName = propFile.getName().replace(".signature.gmt", "");
224
+ // sdsName = NamingUtil.getUniqueName(sdsName, em.getSignatureDataSets().keySet());
225
+ EMSignatureDataSet sigDataSet = new EMSignatureDataSet (em , SIG_DATA_SET_NAME );
157
226
em .addSignatureDataSet (sigDataSet );
158
227
SetOfGeneSets sigGeneSets = sigDataSet .getGeneSetsOfInterest ();
159
228
@@ -254,8 +323,7 @@ public void loadSession(CySession session) {
254
323
255
324
//this is an extra rank file for backwards compatability. Ignore it.
256
325
else if ((file_name_tokens .length == 4 )
257
- && (file_name_tokens [1 ].equals ("Dataset 1" )
258
- || file_name_tokens [1 ].equals ("Dataset 2" ))
326
+ && (file_name_tokens [1 ].equals ("Dataset 1" ) || file_name_tokens [1 ].equals ("Dataset 2" ))
259
327
&& file_name_tokens [2 ].equals ("RANKS" ))
260
328
continue ;
261
329
else //file name is not structured properly --> default to file name
@@ -268,8 +336,7 @@ else if ((file_name_tokens.length == 4)
268
336
if (parts .dataset != null )
269
337
em .getDataSet (parts .dataset ).getExpressionSets ().addRanks (parts .ranks_name , new_ranking );
270
338
else
271
- em .getDataSet (LegacySupport .DATASET1 ).getExpressionSets ().addRanks (parts .ranks_name ,
272
- new_ranking );
339
+ em .getDataSet (LegacySupport .DATASET1 ).getExpressionSets ().addRanks (parts .ranks_name , new_ranking );
273
340
}
274
341
275
342
//Deal with legacy issues
@@ -303,14 +370,11 @@ else if ((file_name_tokens.length == 4)
303
370
Ranking new_ranking ;
304
371
305
372
// Check to see if there is already GSEARanking
306
- if (em .getDataSet (LegacySupport .DATASET2 ).getExpressionSets ().getAllRanksNames ()
307
- .contains (Ranking .GSEARanking )) {
308
- new_ranking = em .getDataSet (LegacySupport .DATASET2 ).getExpressionSets ()
309
- .getRanksByName (Ranking .GSEARanking );
373
+ if (em .getDataSet (LegacySupport .DATASET2 ).getExpressionSets ().getAllRanksNames ().contains (Ranking .GSEARanking )) {
374
+ new_ranking = em .getDataSet (LegacySupport .DATASET2 ).getExpressionSets ().getRanksByName (Ranking .GSEARanking );
310
375
} else {
311
376
new_ranking = new Ranking ();
312
- em .getDataSet (LegacySupport .DATASET2 ).getExpressionSets ().addRanks (Ranking .GSEARanking ,
313
- new_ranking );
377
+ em .getDataSet (LegacySupport .DATASET2 ).getExpressionSets ().addRanks (Ranking .GSEARanking , new_ranking );
314
378
}
315
379
316
380
if (propFile .getName ().contains (".RANKS2.txt" )) {
@@ -323,19 +387,6 @@ else if ((file_name_tokens.length == 4)
323
387
}
324
388
325
389
326
-
327
-
328
-
329
-
330
-
331
-
332
-
333
-
334
-
335
-
336
-
337
-
338
-
339
390
//load the expression files. Load them last because they require
340
391
//info from the parameters
341
392
for (int i = 0 ; i < fileList .size (); i ++){
@@ -491,7 +542,6 @@ private FileNameParts ParseFileName(File filename){
491
542
public CyNetwork getNetworkByName (String name ){
492
543
Set <CyNetwork > networks = cyNetworkManager .getNetworkSet ();
493
544
for (CyNetwork network :networks ){
494
-
495
545
String currentName = network .getRow (network ).get (CyNetwork .NAME ,String .class );
496
546
if (currentName .equals (name ))
497
547
return network ;
0 commit comments