Author: ruschein
Date: 2011-08-16 15:18:15 -0700 (Tue, 16 Aug 2011)
New Revision: 26580
Modified:
core3/impl/trunk/io-impl/src/main/java/org/cytoscape/io/internal/read/sif/Interaction.java
core3/impl/trunk/io-impl/src/main/java/org/cytoscape/io/internal/read/sif/SIFNetworkReader.java
core3/impl/trunk/io-impl/src/test/java/org/cytoscape/io/internal/read/sif/InteractionTest.java
Log:
Optimisation: do not recompile the SIF delimiter pattern for each line read.
Modified:
core3/impl/trunk/io-impl/src/main/java/org/cytoscape/io/internal/read/sif/Interaction.java
===================================================================
---
core3/impl/trunk/io-impl/src/main/java/org/cytoscape/io/internal/read/sif/Interaction.java
2011-08-16 22:15:03 UTC (rev 26579)
+++
core3/impl/trunk/io-impl/src/main/java/org/cytoscape/io/internal/read/sif/Interaction.java
2011-08-16 22:18:15 UTC (rev 26580)
@@ -1,15 +1,8 @@
/*
File: Interaction.java
- Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2011, The Cytoscape Consortium (www.cytoscape.org)
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
@@ -33,23 +26,25 @@
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
+*/
package org.cytoscape.io.internal.read.sif;
+
import java.util.ArrayList;
import java.util.List;
+import java.util.regex.Pattern;
+
/**
* Utility class for representing one line of SIF file.
*/
final class Interaction {
-
private final String source;
private List<String> targets;
private String interactionType;
- Interaction(final String rawText, final String delimiter) {
- final String[] values = rawText.split(delimiter);
+ Interaction(final String rawText, final Pattern delimiterPattern) {
+ final String[] values = delimiterPattern.split(rawText);
if (values.length < 1)
throw new IllegalArgumentException("Invalid entry.");
Modified:
core3/impl/trunk/io-impl/src/main/java/org/cytoscape/io/internal/read/sif/SIFNetworkReader.java
===================================================================
---
core3/impl/trunk/io-impl/src/main/java/org/cytoscape/io/internal/read/sif/SIFNetworkReader.java
2011-08-16 22:15:03 UTC (rev 26579)
+++
core3/impl/trunk/io-impl/src/main/java/org/cytoscape/io/internal/read/sif/SIFNetworkReader.java
2011-08-16 22:18:15 UTC (rev 26580)
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2010-2011, The Cytoscape Consortium (www.cytoscape.org)
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
@@ -24,15 +24,17 @@
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
+*/
package org.cytoscape.io.internal.read.sif;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
+import java.util.regex.Pattern;
import org.cytoscape.event.CyEventHelper;
import org.cytoscape.io.internal.read.AbstractNetworkReader;
@@ -101,34 +103,35 @@
final CyTable nodeTable = network.getDefaultNodeTable();
final CyTable edgeTable = network.getDefaultEdgeTable();
- // Generate bundled event to avoid too many events
problem.
+ // Generate bundled event to avoid too many events problem.
- final String firstLine = br.readLine();
- if (firstLine.contains(TAB))
- delimiter = TAB;
- createEdge(new Interaction(firstLine.trim(),
delimiter), network, nMap);
+ final String firstLine = br.readLine();
+ if (firstLine.contains(TAB))
+ delimiter = TAB;
+ final Pattern delimiterPattern = Pattern.compile(delimiter);
+ createEdge(new Interaction(firstLine.trim(), delimiterPattern),
network, nMap);
- while ((line = br.readLine()) != null) {
- if (cancelled) {
- // Cancel called. Clean up the garbage.
- nMap.clear();
- nMap = null;
- network = null;
- br.close();
- return;
- }
+ while ((line = br.readLine()) != null) {
+ if (cancelled) {
+ // Cancel called. Clean up the garbage.
+ nMap.clear();
+ nMap = null;
+ network = null;
+ br.close();
+ return;
+ }
- if (line.trim().length() <= 0)
- continue;
+ if (line.trim().length() <= 0)
+ continue;
- try {
- final Interaction itr = new
Interaction(line, delimiter);
- createEdge(itr, network, nMap);
- } catch (Exception e) {
- // Simply ignore invalid lines.
- continue;
- }
+ try {
+ final Interaction itr = new Interaction(line,
delimiterPattern);
+ createEdge(itr, network, nMap);
+ } catch (Exception e) {
+ // Simply ignore invalid lines.
+ continue;
}
+ }
br.close();
tm.setStatusMessage("Network data loaded from data
source.\nCreating Cytoscape network...");
Modified:
core3/impl/trunk/io-impl/src/test/java/org/cytoscape/io/internal/read/sif/InteractionTest.java
===================================================================
---
core3/impl/trunk/io-impl/src/test/java/org/cytoscape/io/internal/read/sif/InteractionTest.java
2011-08-16 22:15:03 UTC (rev 26579)
+++
core3/impl/trunk/io-impl/src/test/java/org/cytoscape/io/internal/read/sif/InteractionTest.java
2011-08-16 22:18:15 UTC (rev 26580)
@@ -1,15 +1,8 @@
/*
File: InteractionTest.java
- Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2011, The Cytoscape Consortium (www.cytoscape.org)
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
@@ -34,15 +27,16 @@
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-
-
package org.cytoscape.io.internal.read.sif;
+
+import java.util.regex.Pattern;
import static org.junit.Assert.*;
import org.junit.Test;
+
public class InteractionTest {
- private String delim = " ";
+ private Pattern delim = Pattern.compile(" ");
@Test
public void test3ArgCtor() throws Exception {
--
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.