Author: kono
Date: 2011-12-12 16:28:47 -0800 (Mon, 12 Dec 2011)
New Revision: 27776
Modified:
core3/impl/trunk/psi-mi-impl/src/main/java/org/cytoscape/psi_mi/internal/plugin/PsiMiTabParser.java
core3/impl/trunk/psi-mi-impl/src/main/java/org/cytoscape/psi_mi/internal/plugin/PsiMiTabReader.java
Log:
Progress bar code had been modified.
Modified:
core3/impl/trunk/psi-mi-impl/src/main/java/org/cytoscape/psi_mi/internal/plugin/PsiMiTabParser.java
===================================================================
---
core3/impl/trunk/psi-mi-impl/src/main/java/org/cytoscape/psi_mi/internal/plugin/PsiMiTabParser.java
2011-12-12 22:28:45 UTC (rev 27775)
+++
core3/impl/trunk/psi-mi-impl/src/main/java/org/cytoscape/psi_mi/internal/plugin/PsiMiTabParser.java
2011-12-13 00:28:47 UTC (rev 27776)
@@ -6,10 +6,8 @@
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -20,6 +18,7 @@
import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTable;
import org.cytoscape.model.CyTableEntry;
+import org.cytoscape.work.TaskMonitor;
public class PsiMiTabParser {
@@ -37,10 +36,8 @@
private static final String INTERACTION = "interaction";
// Attr Names
- private static final String DETECTION_METHOD = ATTR_PREFIX
- + "interaction detection method";
- private static final String INTERACTION_TYPE = ATTR_PREFIX
- + "interaction type";
+ private static final String DETECTION_METHOD = ATTR_PREFIX +
"interaction detection method";
+ private static final String INTERACTION_TYPE = ATTR_PREFIX +
"interaction type";
private static final String SOURCE_DB = ATTR_PREFIX + "source database";
private static final String INTERACTION_ID = ATTR_PREFIX + "Interaction
ID";
private static final String EDGE_SCORE = ATTR_PREFIX + "confidence
score";
@@ -52,32 +49,30 @@
private static final String CHEBI = "chebi";
- private static final String INTERACTOR_TYPE = ATTR_PREFIX
- + "interactor type";
+ private static final String INTERACTOR_TYPE = ATTR_PREFIX + "interactor
type";
private static final String COMPOUND = "compound";
private Matcher matcher;
-
- private final Map<String, CyNode> nodeMap;
+ private Map<String, CyNode> nodeMap;
+
private final InputStream inputStream;
private final CyNetworkFactory cyNetworkFactory;
- public PsiMiTabParser(final InputStream inputStream,
- final CyNetworkFactory cyNetworkFactory) {
+ public PsiMiTabParser(final InputStream inputStream, final
CyNetworkFactory cyNetworkFactory) {
this.inputStream = inputStream;
this.cyNetworkFactory = cyNetworkFactory;
- this.nodeMap = new HashMap<String, CyNode>();
-
}
- public CyNetwork parse() throws IOException {
+ public CyNetwork parse(final TaskMonitor taskMonitor) throws
IOException {
+ this.nodeMap = new HashMap<String, CyNode>();
+
String[] entry;
String[] sourceID;
String[] targetID;
String[] detectionMethods;
-
+
String[] sourceDB;
String[] interactionID;
String[] interactionType;
@@ -85,38 +80,38 @@
String[] edgeScore;
final CyNetwork network = cyNetworkFactory.createNetwork();
-
+
final CyTable nodeTable = network.getDefaultNodeTable();
- if(nodeTable.getColumn(INTERACTOR_TYPE) == null)
+ if (nodeTable.getColumn(INTERACTOR_TYPE) == null)
nodeTable.createColumn(INTERACTOR_TYPE, String.class,
false);
- if(nodeTable.getColumn(INTERACTOR_TYPE + ".name") == null)
+ if (nodeTable.getColumn(INTERACTOR_TYPE + ".name") == null)
nodeTable.createColumn(INTERACTOR_TYPE + ".name",
String.class, false);
-
+
final CyTable edgeTable = network.getDefaultEdgeTable();
- if(edgeTable.getColumn(INTERACTION_ID) == null)
+ if (edgeTable.getColumn(INTERACTION_ID) == null)
edgeTable.createColumn(INTERACTION_ID, String.class,
false);
- if(edgeTable.getColumn(INTERACTION_TYPE) == null) {
+ if (edgeTable.getColumn(INTERACTION_TYPE) == null) {
edgeTable.createListColumn(INTERACTION_TYPE,
String.class, false);
edgeTable.createListColumn(INTERACTION_TYPE + ".name",
String.class, false);
}
- if(edgeTable.getColumn(DETECTION_METHOD) == null) {
+ if (edgeTable.getColumn(DETECTION_METHOD) == null) {
edgeTable.createListColumn(DETECTION_METHOD,
String.class, false);
edgeTable.createListColumn(DETECTION_METHOD + ".name",
String.class, false);
}
- if(edgeTable.getColumn(SOURCE_DB) == null)
+ if (edgeTable.getColumn(SOURCE_DB) == null)
edgeTable.createListColumn(SOURCE_DB, String.class,
false);
- if(edgeTable.getColumn(EDGE_SCORE) == null)
+ if (edgeTable.getColumn(EDGE_SCORE) == null)
edgeTable.createListColumn(EDGE_SCORE, Double.class,
false);
-
String line;
final BufferedReader br = new BufferedReader(new
InputStreamReader(inputStream));
+ long interactionCount = 0;
while ((line = br.readLine()) != null) {
// Ignore comment line
- if(line.startsWith("#"))
+ if (line.startsWith("#"))
continue;
-
+
try {
entry = line.split(TAB);
@@ -128,18 +123,18 @@
targetID = entry[1].split(SEPARATOR);
final String sourceRawID =
sourceID[0].split(":")[1];
final String targetRawID =
targetID[0].split(":")[1];
-
+
CyNode source = nodeMap.get(sourceRawID);
- if(source == null) {
+ if (source == null) {
source = network.addNode();
nodeMap.put(sourceRawID, source);
}
CyNode target = nodeMap.get(targetRawID);
- if(target == null) {
+ if (target == null) {
target = network.addNode();
nodeMap.put(targetRawID, target);
}
-
+
network.getRow(source).set(CyTableEntry.NAME,
sourceRawID);
network.getRow(target).set(CyTableEntry.NAME,
targetRawID);
@@ -182,8 +177,9 @@
network.getRow(e).set(INTERACTION_ID,
interactionID[0]);
- setPublication(network.getRow(e),
entry[8].split(SEPARATOR),
- entry[7].split(SEPARATOR));
+ setPublication(network.getRow(e),
entry[8].split(SEPARATOR), entry[7].split(SEPARATOR));
+ interactionCount++;
+ taskMonitor.setStatusMessage(interactionCount +
" interactions loaded.");
} catch (Exception ex) {
ex.printStackTrace();
continue;
@@ -193,7 +189,8 @@
br.close();
nodeMap.clear();
-
+ nodeMap = null;
+
return network;
}
@@ -203,18 +200,17 @@
String taxonName;
if (buf != null && buf.length == 2) {
attrName = ATTR_PREFIX + buf[0];
-
- if(row.getTable().getColumn(attrName) == null) {
+
+ if (row.getTable().getColumn(attrName) == null) {
row.getTable().createColumn(attrName,
String.class, false);
row.getTable().createColumn(attrName + ".name",
String.class, false);
}
-
+
matcher = miNamePttr.matcher(buf[1]);
if (matcher.find()) {
taxonName = matcher.group();
row.set(attrName, buf[1].split("\\(")[0]);
- row.set(attrName + ".name",
- taxonName.substring(1,
taxonName.length() - 1));
+ row.set(attrName + ".name",
taxonName.substring(1, taxonName.length() - 1));
} else {
row.set(attrName, buf[1]);
}
@@ -284,17 +280,17 @@
scoreString = parts[1];
scoreType = parts[0];
final String colName = key + "." + scoreType;
-
- if(row.getTable().getColumn(colName) == null)
+
+ if (row.getTable().getColumn(colName) == null)
row.getTable().createListColumn(colName,
Double.class, false);
try {
final Double score =
Double.parseDouble(scoreString);
row.set(key + "." + scoreType, score);
} catch (Exception e) {
-// if (scoreString != null
-// &&
scoreString.trim().equals("") == false)
-// row.set(key + "." + scoreType,
scoreString);
+ // if (scoreString != null
+ // && scoreString.trim().equals("") == false)
+ // row.set(key + "." + scoreType, scoreString);
continue;
}
@@ -302,9 +298,9 @@
}
private void listAttrMapper(CyRow row, String attrName, String value) {
- if(row.getTable().getColumn(attrName) == null)
+ if (row.getTable().getColumn(attrName) == null)
row.getTable().createListColumn(attrName, String.class,
false);
-
+
List<String> currentAttr = row.getList(attrName, String.class);
if (currentAttr == null) {
Modified:
core3/impl/trunk/psi-mi-impl/src/main/java/org/cytoscape/psi_mi/internal/plugin/PsiMiTabReader.java
===================================================================
---
core3/impl/trunk/psi-mi-impl/src/main/java/org/cytoscape/psi_mi/internal/plugin/PsiMiTabReader.java
2011-12-12 22:28:45 UTC (rev 27775)
+++
core3/impl/trunk/psi-mi-impl/src/main/java/org/cytoscape/psi_mi/internal/plugin/PsiMiTabReader.java
2011-12-13 00:28:47 UTC (rev 27776)
@@ -22,17 +22,14 @@
private InputStream inputStream;
private final CyNetworkViewFactory cyNetworkViewFactory;
-
private final CyLayoutAlgorithmManager layouts;
private final PsiMiTabParser parser;
-
private CyNetwork network;
private TaskMonitor parentTaskMonitor;
-
private final CyProperty<Properties> prop;
-
+
public PsiMiTabReader(InputStream is,
CyNetworkViewFactory cyNetworkViewFactory,
CyNetworkFactory cyNetworkFactory, final
CyLayoutAlgorithmManager layouts, final CyProperty<Properties> prop) {
@@ -60,13 +57,11 @@
}
private void createNetwork(TaskMonitor taskMonitor) throws IOException {
-
- taskMonitor.setProgress(0.0);
-
- network = parser.parse();
- taskMonitor.setProgress(1.0);
-
+ taskMonitor.setStatusMessage("Loading PSI-MI-TAB file.");
+ taskMonitor.setProgress(0.01d);
+ network = parser.parse(taskMonitor);
+ taskMonitor.setProgress(0.4d);
}
@Override
@@ -95,6 +90,7 @@
throw new RuntimeException("Could not finish layout",
e);
}
+ parentTaskMonitor.setProgress(1.0d);
return view;
}
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.