Author: ruschein Date: 2010-11-10 08:48:35 -0800 (Wed, 10 Nov 2010) New Revision: 22794
Added: core3/equations-functions-impl/trunk/ core3/equations-functions-impl/trunk/pom.xml core3/equations-functions-impl/trunk/src/ core3/equations-functions-impl/trunk/src/main/ core3/equations-functions-impl/trunk/src/main/java/ core3/equations-functions-impl/trunk/src/main/java/org/ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/FunctionRegistrar.java core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToEdgeMapper.java core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToNodeMapper.java core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/Degree.java core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/InDegree.java core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/OutDegree.java core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/SourceID.java core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/TargetID.java core3/equations-functions-impl/trunk/src/main/resources/ core3/equations-functions-impl/trunk/src/main/resources/META-INF/ core3/equations-functions-impl/trunk/src/main/resources/META-INF/spring/ core3/equations-functions-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml core3/equations-functions-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml Log: Port from Cytoscape 2.8. Added: core3/equations-functions-impl/trunk/pom.xml =================================================================== --- core3/equations-functions-impl/trunk/pom.xml (rev 0) +++ core3/equations-functions-impl/trunk/pom.xml 2010-11-10 16:48:35 UTC (rev 22794) @@ -0,0 +1,182 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <parent> + <artifactId>parent</artifactId> + <groupId>org.cytoscape</groupId> + <version>3.0.0-alpha3</version> + </parent> + + <properties> + <bundle.symbolicName>org.cytoscape.equations-functions-impl</bundle.symbolicName> + <bundle.namespace>org.cytoscape.equations</bundle.namespace> + </properties> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.cytoscape</groupId> + <artifactId>equations-functions-impl</artifactId> + <version>1.0-SNAPSHOT</version> + + <name>${bundle.symbolicName}</name> + + <packaging>bundle</packaging> + + <scm> + <connection>scm:svn:http://chianti.ucsd.edu/svn/core3/equations-impl/trunk</connection> + <developerConnection>scm:svn:svn+ssh://grenache.ucsd.edu/cellar/common/svn/core3/equations-impl/trunk</developerConnection> + <url>http://chianti.ucsd.edu/svn/core3/equations-impl/trunk</url> + </scm> + + + + <repositories> + <!-- + bootstrap for cytoscape dependencies, namely the parent POM snapshots + --> + <repository> + <id>cytoscape_snapshots</id> + <snapshots> + <enabled>true</enabled> + </snapshots> + <releases> + <enabled>false</enabled> + </releases> + <name>Cytoscape Snapshots</name> + <url>http://cytoscape.wodaklab.org/nexus/content/repositories/snapshots/</url> + </repository> + <!-- + bootstrap for cytoscape dependencies, namely the parent POM releases + --> + <repository> + <id>cytoscape_releases</id> + <snapshots> + <enabled>false</enabled> + </snapshots> + <releases> + <enabled>true</enabled> + </releases> + <name>Cytoscape Releases</name> + <url>http://cytoscape.wodaklab.org/nexus/content/repositories/releases/</url> + </repository> + </repositories> + + <build> + <resources> + <resource> + <directory>src/main/resources</directory> + </resource> + <resource> + <directory>src/integration/resources</directory> + </resource> + <resource> + <directory>.</directory> + <includes> + <include>plugin.xml</include> + <include>plugin.properties</include> + <include>icons/**</include> + </includes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.ops4j</groupId> + <artifactId>maven-pax-plugin</artifactId> + <version>1.4</version> + <!-- + | enable improved OSGi compilation support for the bundle + life-cycle. | to switch back to the standard bundle life-cycle, + move this setting | down to the maven-bundle-plugin section + --> + <extensions>true</extensions> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>1.4.3</version> + <!-- + | the following instructions build a simple set of public/private + classes into an OSGi bundle + --> + <configuration> + <instructions> + <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName> + <Bundle-Version>${pom.version}</Bundle-Version> + <!-- + | assume public classes are in the top package, and private + classes are under ".internal" + --> + <!-- + | each module can override these defaults in their osgi.bnd file + --> + <_include>-osgi.bnd</_include> + </instructions> + </configuration> + </plugin> + <plugin> + <artifactId>maven-clean-plugin</artifactId> + <version>2.4.1</version> + <configuration> + <filesets> + <fileset> + <directory>${basedir}/eclipse_config</directory> + </fileset> + </filesets> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>1.5</version> + <executions> + <execution> + <id>add-test-source</id> + <phase>generate-test-sources</phase> + <goals> + <goal>add-test-source</goal> + </goals> + <configuration> + <sources> + <source>${basedir}/src/integration/java</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.cytoscape</groupId> + <artifactId>equations-api</artifactId> + <version>3.0.0-alpha2-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.cytoscape</groupId> + <artifactId>equations-impl</artifactId> + <version>3.0.0-alpha3</version> + </dependency> + <dependency> + <groupId>org.cytoscape</groupId> + <artifactId>model-api</artifactId> + <version>3.0.0-alpha2-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.cytoscape</groupId> + <artifactId>session-api</artifactId> + <version>3.0.0-alpha2-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.logging</groupId> + <artifactId>pax-logging-api</artifactId> + <version>1.5.2</version> + </dependency> + </dependencies> +</project> Added: core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/FunctionRegistrar.java =================================================================== --- core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/FunctionRegistrar.java (rev 0) +++ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/FunctionRegistrar.java 2010-11-10 16:48:35 UTC (rev 22794) @@ -0,0 +1,36 @@ +package org.cytoscape.equations.internal; + + +import org.cytoscape.equations.EqnCompiler; +import org.cytoscape.equations.EqnParser; +import org.cytoscape.equations.internal.functions.*; +import org.cytoscape.session.CyApplicationManager; + + +public class FunctionRegistrar { + private final EqnCompiler compiler; + private final CyApplicationManager applicationManager; + private final SUIDToNodeMapper suidToNodeMapper; + private final SUIDToEdgeMapper suidToEdgeMapper; + + public FunctionRegistrar(final EqnCompiler compiler, final CyApplicationManager applicationManager, + final SUIDToNodeMapper suidToNodeMapper, + final SUIDToEdgeMapper suidToEdgeMapper) + { + this.compiler = compiler; + this.applicationManager = applicationManager; + this.suidToNodeMapper = suidToNodeMapper; + this.suidToEdgeMapper = suidToEdgeMapper; + + registerAllFunctions(); + } + + private void registerAllFunctions() { + final EqnParser parser = compiler.getParser(); + parser.registerFunction(new Degree(applicationManager, suidToNodeMapper)); + parser.registerFunction(new InDegree(suidToNodeMapper, applicationManager)); + parser.registerFunction(new OutDegree(suidToNodeMapper, applicationManager)); + parser.registerFunction(new SourceID(suidToEdgeMapper)); + parser.registerFunction(new TargetID(suidToEdgeMapper)); + } +} \ No newline at end of file Added: core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToEdgeMapper.java =================================================================== --- core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToEdgeMapper.java (rev 0) +++ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToEdgeMapper.java 2010-11-10 16:48:35 UTC (rev 22794) @@ -0,0 +1,30 @@ +package org.cytoscape.equations.internal; + + +import java.util.HashMap; +import java.util.Map; + +import org.cytoscape.model.CyEdge; +import org.cytoscape.model.events.AddedEdgeEvent; +import org.cytoscape.model.events.AddedEdgeListener; +import org.cytoscape.model.events.AboutToRemoveEdgeEvent; +import org.cytoscape.model.events.AboutToRemoveEdgeListener; + + +public class SUIDToEdgeMapper implements AddedEdgeListener, AboutToRemoveEdgeListener { + private final Map<Long, CyEdge> suidToEdgeMap = new HashMap<Long, CyEdge>(); + + public void handleEvent(final AddedEdgeEvent event) { + final CyEdge edge = event.getEdge(); + suidToEdgeMap.put(edge.getSUID(), edge); + } + + public void handleEvent(final AboutToRemoveEdgeEvent event) { + final CyEdge edge = event.getEdge(); + suidToEdgeMap.remove(edge.getSUID()); + } + + public CyEdge getEdge(final Long id) { + return suidToEdgeMap.get(id); + } +} \ No newline at end of file Added: core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToNodeMapper.java =================================================================== --- core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToNodeMapper.java (rev 0) +++ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToNodeMapper.java 2010-11-10 16:48:35 UTC (rev 22794) @@ -0,0 +1,30 @@ +package org.cytoscape.equations.internal; + + +import java.util.HashMap; +import java.util.Map; + +import org.cytoscape.model.CyNode; +import org.cytoscape.model.events.AddedNodeEvent; +import org.cytoscape.model.events.AddedNodeListener; +import org.cytoscape.model.events.AboutToRemoveNodeEvent; +import org.cytoscape.model.events.AboutToRemoveNodeListener; + + +public class SUIDToNodeMapper implements AddedNodeListener, AboutToRemoveNodeListener { + private final Map<Long, CyNode> suidToNodeMap = new HashMap<Long, CyNode>(); + + public void handleEvent(final AddedNodeEvent event) { + final CyNode edge = event.getNode(); + suidToNodeMap.put(edge.getSUID(), edge); + } + + public void handleEvent(final AboutToRemoveNodeEvent event) { + final CyNode edge = event.getNode(); + suidToNodeMap.remove(edge.getSUID()); + } + + public CyNode getNode(final Long id) { + return suidToNodeMap.get(id); + } +} \ No newline at end of file Added: core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/Degree.java =================================================================== --- core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/Degree.java (rev 0) +++ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/Degree.java 2010-11-10 16:48:35 UTC (rev 22794) @@ -0,0 +1,118 @@ +/* + File: Degree.java + + Copyright (c) 2010, 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 + by the Free Software Foundation; either version 2.1 of the License, or + any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF + MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and + documentation provided hereunder is on an "as is" basis, and the + Institute for Systems Biology and the Whitehead Institute + have no obligations to provide maintenance, support, + updates, enhancements or modifications. In no event shall the + Institute for Systems Biology and the Whitehead Institute + be liable to any party for direct, indirect, special, + incidental or consequential damages, including lost profits, arising + out of the use of this software and its documentation, even if the + Institute for Systems Biology and the Whitehead Institute + have been advised of the possibility of such damage. See + the GNU Lesser General Public License for more details. + + 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.equations.internal.functions; + + +import java.util.ArrayList; +import java.util.List; + +import org.cytoscape.model.CyEdge; +import org.cytoscape.model.CyNetwork; +import org.cytoscape.model.CyNode; +import org.cytoscape.equations.Function; +import org.cytoscape.equations.internal.SUIDToNodeMapper; +import org.cytoscape.session.CyApplicationManager; + + +public class Degree implements Function { + private final CyApplicationManager applicationManager; + private final SUIDToNodeMapper suidToNodeMapper; + + public Degree(final CyApplicationManager applicationManager, final SUIDToNodeMapper suidToNodeMapper) { + this.applicationManager = applicationManager; + this.suidToNodeMapper = suidToNodeMapper; + } + + /** + * Used to parse the function string. This name is treated in a case-insensitive manner! + * @return the name by which you must call the function when used in an attribute equation. + */ + public String getName() { return "DEGREE"; } + + /** + * Used to provide help for users. + * @return a description of what this function does + */ + public String getFunctionSummary() { return "Returns degree of a node."; } + + /** + * Used to provide help for users. + * @return a description of how to use this function + */ + public String getUsageDescription() { return "Call this with \"DEGREE(node_ID)\""; } + + public Class getReturnType() { return Long.class; } + + /** + * @return String.class or null if there is not exactly 1 arg or the arg is not of type String + */ + public Class validateArgTypes(final Class[] argTypes) { + if (argTypes.length != 1 || (argTypes[0] != Long.class)) + return null; + + return Long.class; + } + + /** + * @param args the function arguments which must be either one object of type Double or Long + * @return the result of the function evaluation which is the natural logarithm of the first argument + */ + public Object evaluateFunction(final Object[] args) { + final Long nodeID = (Long)args[0]; + + final CyNetwork currentNetwork = applicationManager.getCurrentNetwork(); + if (currentNetwork == null) + return (Long)(-1L); + + final CyNode node = suidToNodeMapper.getNode(nodeID); + if (node == null) + throw new IllegalArgumentException("\"" + nodeID + "\" is not a valid node identifier!"); + + return (Long)(long)currentNetwork.getAdjacentEdgeList(node, CyEdge.Type.ANY).size(); + } + + /** + * Used with the equation builder. + * + * @param leadingArgs the types of the arguments that have already been selected by the user. + * @return the set of arguments (must be a collection of String.class, Long.class, Double.class, + * Boolean.class and List.class) that are candidates for the next argument. An empty + * set indicates that no further arguments are valid. + */ + public List<Class> getPossibleArgTypes(final Class[] leadingArgs) { + if (leadingArgs.length == 0) { + final List<Class> possibleNextArgs = new ArrayList<Class>(); + possibleNextArgs.add(String.class); + return possibleNextArgs; + } + + return null; + } +} Added: core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/InDegree.java =================================================================== --- core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/InDegree.java (rev 0) +++ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/InDegree.java 2010-11-10 16:48:35 UTC (rev 22794) @@ -0,0 +1,88 @@ +/* + File: InDegree.java + + Copyright (c) 2010, 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 + by the Free Software Foundation; either version 2.1 of the License, or + any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF + MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and + documentation provided hereunder is on an "as is" basis, and the + Institute for Systems Biology and the Whitehead Institute + have no obligations to provide maintenance, support, + updates, enhancements or modifications. In no event shall the + Institute for Systems Biology and the Whitehead Institute + be liable to any party for direct, indirect, special, + incidental or consequential damages, including lost profits, arising + out of the use of this software and its documentation, even if the + Institute for Systems Biology and the Whitehead Institute + have been advised of the possibility of such damage. See + the GNU Lesser General Public License for more details. + + 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.equations.internal.functions; + + +import org.cytoscape.model.CyEdge; +import org.cytoscape.model.CyNetwork; +import org.cytoscape.model.CyNode; + +import org.cytoscape.equations.AbstractFunction; +import org.cytoscape.equations.ArgDescriptor; +import org.cytoscape.equations.ArgType; +import org.cytoscape.equations.internal.SUIDToNodeMapper; + +import org.cytoscape.session.CyApplicationManager; + + +public class InDegree extends AbstractFunction { + private final SUIDToNodeMapper suidToNodeMapper; + private final CyApplicationManager applicationManager; + + public InDegree(final SUIDToNodeMapper suidToNodeMapper, + final CyApplicationManager applicationManager) + { + super(new ArgDescriptor[] { new ArgDescriptor(ArgType.STRICT_INT, "node_ID", "An ID identifying a node.") }); + this.suidToNodeMapper = suidToNodeMapper; + this.applicationManager = applicationManager; + } + + /** + * Used to parse the function string. This name is treated in a case-insensitive manner! + * @return the name by which you must call the function when used in an attribute equation. + */ + public String getName() { return "INDEGREE"; } + + /** + * Used to provide help for users. + * @return a description of what this function does + */ + public String getFunctionSummary() { return "Returns indegree of a node."; } + + public Class getReturnType() { return Long.class; } + + /** + * @param args the function arguments which must be either one object of type Double or Long + * @return the result of the function evaluation which is the natural logarithm of the first argument + */ + public Object evaluateFunction(final Object[] args) { + final Long nodeID = (Long)args[0]; + + final CyNetwork currentNetwork = applicationManager.getCurrentNetwork(); + if (currentNetwork == null) + return (Long)(-1L); + + final CyNode node = suidToNodeMapper.getNode(nodeID); + if (node == null) + throw new IllegalArgumentException("\"" + nodeID + "\" is not a valid node identifier!"); + + return (Long)(long)currentNetwork.getAdjacentEdgeList(node, CyEdge.Type.INCOMING).size(); + } +} Added: core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/OutDegree.java =================================================================== --- core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/OutDegree.java (rev 0) +++ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/OutDegree.java 2010-11-10 16:48:35 UTC (rev 22794) @@ -0,0 +1,88 @@ +/* + File: OutDegree.java + + Copyright (c) 2010, 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 + by the Free Software Foundation; either version 2.1 of the License, or + any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF + MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and + documentation provided hereunder is on an "as is" basis, and the + Institute for Systems Biology and the Whitehead Institute + have no obligations to provide maintenance, support, + updates, enhancements or modifications. In no event shall the + Institute for Systems Biology and the Whitehead Institute + be liable to any party for direct, indirect, special, + incidental or consequential damages, including lost profits, arising + out of the use of this software and its documentation, even if the + Institute for Systems Biology and the Whitehead Institute + have been advised of the possibility of such damage. See + the GNU Lesser General Public License for more details. + + 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.equations.internal.functions; + + +import org.cytoscape.model.CyEdge; +import org.cytoscape.model.CyNetwork; +import org.cytoscape.model.CyNode; + +import org.cytoscape.equations.AbstractFunction; +import org.cytoscape.equations.ArgDescriptor; +import org.cytoscape.equations.ArgType; +import org.cytoscape.equations.internal.SUIDToNodeMapper; + +import org.cytoscape.session.CyApplicationManager; + + +public class OutDegree extends AbstractFunction { + private final SUIDToNodeMapper suidToNodeMapper; + private final CyApplicationManager applicationManager; + + public OutDegree(final SUIDToNodeMapper suidToNodeMapper, + final CyApplicationManager applicationManager) + { + super(new ArgDescriptor[] { new ArgDescriptor(ArgType.STRICT_INT, "node_ID", "An ID identifying a node.") }); + this.suidToNodeMapper = suidToNodeMapper; + this.applicationManager = applicationManager; + } + + /** + * Used to parse the function string. This name is treated in a case-insensitive manner! + * @return the name by which you must call the function when used in an attribute equation. + */ + public String getName() { return "OUTDEGREE"; } + + /** + * Used to provide help for users. + * @return a description of what this function does + */ + public String getFunctionSummary() { return "Returns indegree of a node."; } + + public Class getReturnType() { return Long.class; } + + /** + * @param args the function arguments which must be either one object of type Double or Long + * @return the result of the function evaluation which is the natural logarithm of the first argument + */ + public Object evaluateFunction(final Object[] args) { + final Long nodeID = (Long)args[0]; + + final CyNetwork currentNetwork = applicationManager.getCurrentNetwork(); + if (currentNetwork == null) + return (Long)(-1L); + + final CyNode node = suidToNodeMapper.getNode(nodeID); + if (node == null) + throw new IllegalArgumentException("\"" + nodeID + "\" is not a valid node identifier!"); + + return (Long)(long)currentNetwork.getAdjacentEdgeList(node, CyEdge.Type.OUTGOING).size(); + } +} Added: core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/SourceID.java =================================================================== --- core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/SourceID.java (rev 0) +++ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/SourceID.java 2010-11-10 16:48:35 UTC (rev 22794) @@ -0,0 +1,79 @@ +/* + File: SourceID.java + + Copyright (c) 2010, 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 + by the Free Software Foundation; either version 2.1 of the License, or + any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF + MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and + documentation provided hereunder is on an "as is" basis, and the + Institute for Systems Biology and the Whitehead Institute + have no obligations to provide maintenance, support, + updates, enhancements or modifications. In no event shall the + Institute for Systems Biology and the Whitehead Institute + be liable to any party for direct, indirect, special, + incidental or consequential damages, including lost profits, arising + out of the use of this software and its documentation, even if the + Institute for Systems Biology and the Whitehead Institute + have been advised of the possibility of such damage. See + the GNU Lesser General Public License for more details. + + 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.equations.internal.functions; + + +import org.cytoscape.equations.AbstractFunction; +import org.cytoscape.equations.ArgDescriptor; +import org.cytoscape.equations.ArgType; +import org.cytoscape.equations.internal.SUIDToEdgeMapper; +import org.cytoscape.equations.internal.SUIDToNodeMapper; + +import org.cytoscape.model.CyEdge; + +import org.cytoscape.session.CyApplicationManager; + + +public class SourceID extends AbstractFunction { + private final SUIDToEdgeMapper suidToEdgeMapper; + + public SourceID(final SUIDToEdgeMapper suidToEdgeMapper) { + super(new ArgDescriptor[] { new ArgDescriptor(ArgType.STRICT_INT, "edge_ID", "An ID identifying an edge.") }); + this.suidToEdgeMapper = suidToEdgeMapper; + } + + /** + * Used to parse the function string. This name is treated in a case-insensitive manner! + * @return the name by which you must call the function when used in an attribute equation. + */ + public String getName() { return "SOURCEID"; } + + /** + * Used to provide help for users. + * @return a description of what this function does + */ + public String getFunctionSummary() { return "Returns source ID of an edge."; } + + public Class getReturnType() { return Long.class; } + + /** + * @param args the function arguments which must be either one object of type Double or Long + * @return the result of the function evaluation which is the natural logarithm of the first argument + */ + public Object evaluateFunction(final Object[] args) { + final Long edgeID = (Long)args[0]; + + final CyEdge edge = suidToEdgeMapper.getEdge(edgeID); + if (edge == null) + throw new IllegalArgumentException("\"" + edgeID + "\" is not a valid edge identifier!"); + + return edge.getSource().getSUID(); + } +} Added: core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/TargetID.java =================================================================== --- core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/TargetID.java (rev 0) +++ core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/TargetID.java 2010-11-10 16:48:35 UTC (rev 22794) @@ -0,0 +1,77 @@ +/* + File: TargetID.java + + Copyright (c) 2010, 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 + by the Free Software Foundation; either version 2.1 of the License, or + any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF + MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and + documentation provided hereunder is on an "as is" basis, and the + Institute for Systems Biology and the Whitehead Institute + have no obligations to provide maintenance, support, + updates, enhancements or modifications. In no event shall the + Institute for Systems Biology and the Whitehead Institute + be liable to any party for direct, indirect, special, + incidental or consequential damages, including lost profits, arising + out of the use of this software and its documentation, even if the + Institute for Systems Biology and the Whitehead Institute + have been advised of the possibility of such damage. See + the GNU Lesser General Public License for more details. + + 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.equations.internal.functions; + + +import org.cytoscape.equations.AbstractFunction; +import org.cytoscape.equations.ArgDescriptor; +import org.cytoscape.equations.ArgType; +import org.cytoscape.equations.internal.SUIDToEdgeMapper; +import org.cytoscape.equations.internal.SUIDToNodeMapper; + +import org.cytoscape.model.CyEdge; + + +public class TargetID extends AbstractFunction { + private final SUIDToEdgeMapper suidToEdgeMapper; + + public TargetID(final SUIDToEdgeMapper suidToEdgeMapper) { + super(new ArgDescriptor[] { new ArgDescriptor(ArgType.STRICT_INT, "edge_ID", "An ID identifying an edge.") }); + this.suidToEdgeMapper = suidToEdgeMapper; + } + + /** + * Used to parse the function string. This name is treated in a case-insensitive manner! + * @return the name by which you must call the function when used in an attribute equation. + */ + public String getName() { return "TARGETID"; } + + /** + * Used to provide help for users. + * @return a description of what this function does + */ + public String getFunctionSummary() { return "Returns target ID of an edge."; } + + public Class getReturnType() { return Long.class; } + + /** + * @param args the function arguments which must be either one object of type Double or Long + * @return the result of the function evaluation which is the natural logarithm of the first argument + */ + public Object evaluateFunction(final Object[] args) { + final Long edgeID = (Long)args[0]; + + final CyEdge edge = suidToEdgeMapper.getEdge(edgeID); + if (edge == null) + throw new IllegalArgumentException("\"" + edgeID + "\" is not a valid edge identifier!"); + + return edge.getTarget().getSUID(); + } +} Added: core3/equations-functions-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml =================================================================== --- core3/equations-functions-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml (rev 0) +++ core3/equations-functions-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml 2010-11-10 16:48:35 UTC (rev 22794) @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.0.xsd" + default-lazy-init="false"> + + <!-- imports --> + <osgi:reference id="compilerServiceRef" interface="org.cytoscape.equations.EqnCompiler" /> + <osgi:reference id="applicationManagerServiceRef" interface="org.cytoscape.session.CyApplicationManager" /> + + + <!-- listeners --> + <osgi:service id="suidToEdgeMapperService" ref="suidToEdgeMapper" + auto-export="interfaces"> + </osgi:service> + <osgi:service id="suidToNodeMapperService" ref="suidToNodeMapper" + auto-export="interfaces"> + </osgi:service> +</beans> Added: core3/equations-functions-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml =================================================================== --- core3/equations-functions-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml (rev 0) +++ core3/equations-functions-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml 2010-11-10 16:48:35 UTC (rev 22794) @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-2.5.xsd"> + + <!-- regular spring configuration file defining the beans for this bundle. + We've kept the OSGi definitions in a separate configuration file so that + this file can easily be used for integration testing outside of an OSGi environment --> + + <context:annotation-config /> + + <bean id="suidToEdgeMapper" class="org.cytoscape.equations.internal.SUIDToEdgeMapper" /> + + <bean id="suidToNodeMapper" class="org.cytoscape.equations.internal.SUIDToNodeMapper" /> + + <bean id="functionRegistrar" class="org.cytoscape.equations.internal.FunctionRegistrar>"> + <constructor-arg ref="compilerServiceRef" /> + <constructor-arg ref="applicationManagerServiceRef" /> + <constructor-arg ref="suidToNodeMapper" /> + <constructor-arg ref="suidToEdgeMapper" /> + </bean> +</beans> -- 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.
