Author: ruschein Date: 2010-12-09 14:19:56 -0800 (Thu, 09 Dec 2010) New Revision: 23154
Modified: core3/psi-mi-impl/trunk/pom.xml core3/psi-mi-impl/trunk/src/main/java/org/cytoscape/psi_mi/internal/cyto_mapper/MapToCytoscape.java core3/psi-mi-impl/trunk/src/test/java/org/cytoscape/psi_mi/internal/cyto_mapper/MapToCytoscapeTest.java Log: Updated to track changes in model-api. Modified: core3/psi-mi-impl/trunk/pom.xml =================================================================== --- core3/psi-mi-impl/trunk/pom.xml 2010-12-09 22:19:39 UTC (rev 23153) +++ core3/psi-mi-impl/trunk/pom.xml 2010-12-09 22:19:56 UTC (rev 23154) @@ -1,112 +1,118 @@ <?xml version="1.0" encoding="UTF-8"?> <project - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <parent> - <groupId>org.cytoscape</groupId> - <artifactId>parent</artifactId> - <version>1.0-SNAPSHOT</version> - </parent> - <properties> - <bundle.symbolicName>org.cytoscape.psi-mi-impl</bundle.symbolicName> - <bundle.namespace>org.cytoscape.psi_mi</bundle.namespace> - </properties> - <modelVersion>4.0.0</modelVersion> - <groupId>org.cytoscape</groupId> - <artifactId>psi-mi-impl</artifactId> - <version>1.0-SNAPSHOT</version> - <name>${bundle.symbolicName} - [${bundle.namespace}]</name> - <packaging>bundle</packaging> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <parent> + <groupId>org.cytoscape</groupId> + <artifactId>parent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <properties> + <bundle.symbolicName>org.cytoscape.psi-mi-impl</bundle.symbolicName> + <bundle.namespace>org.cytoscape.psi_mi</bundle.namespace> + </properties> + <modelVersion>4.0.0</modelVersion> + <groupId>org.cytoscape</groupId> + <artifactId>psi-mi-impl</artifactId> + <version>1.0-SNAPSHOT</version> + <name>${bundle.symbolicName} + [${bundle.namespace}]</name> + <packaging>bundle</packaging> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.cytoscape</groupId> + <artifactId>io-api</artifactId> + <version>3.0.0-alpha1</version> + </dependency> + <dependency> + <groupId>org.cytoscape</groupId> + <artifactId>layout-api</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.cytoscape</groupId> + <artifactId>model-api</artifactId> + <version>3.0.0-alpha2-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.cytoscape</groupId> + <artifactId>test-support</artifactId> + <version>1.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <version>1.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>jaxb2-maven-plugin</artifactId> + <executions> + <execution> + <id>mi1</id> + <configuration> + <arguments>-nv</arguments> + <packageName>org.cytoscape.psi_mi.internal.schema.mi1</packageName> + <schemaFiles>MIF1.xsd</schemaFiles> + <staleFile>${project.build.directory}/generated-sources/jaxb/org/cytoscape/psi_mi/internal/schema/mi1/.staleFlag</staleFile> + <clearOutputDir>false</clearOutputDir> + </configuration> + <goals> + <goal>xjc</goal> + </goals> + </execution> + <execution> + <id>mi25</id> + <configuration> + <arguments>-nv</arguments> + <packageName>org.cytoscape.psi_mi.internal.schema.mi25</packageName> + <schemaFiles>MIF25.xsd</schemaFiles> + <staleFile>${project.build.directory}/generated-sources/jaxb/org/cytoscape/psi_mi/internal/schema/mi25/.staleFlag</staleFile> + <clearOutputDir>false</clearOutputDir> + </configuration> + <goals> + <goal>xjc</goal> + </goals> + </execution> + </executions> <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>${junit.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.cytoscape</groupId> - <artifactId>io-api</artifactId> - <version>3.0.0-alpha1</version> - </dependency> - <dependency> - <groupId>org.cytoscape</groupId> - <artifactId>layout-api</artifactId> - <version>1.0-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.cytoscape</groupId> - <artifactId>test-support</artifactId> - <version>1.0-SNAPSHOT</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <version>1.8.1</version> - <scope>test</scope> - </dependency> + <dependency> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + <version>2.8.1</version> + </dependency> </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>jaxb2-maven-plugin</artifactId> - <executions> - <execution> - <id>mi1</id> - <configuration> - <arguments>-nv</arguments> - <packageName>org.cytoscape.psi_mi.internal.schema.mi1</packageName> - <schemaFiles>MIF1.xsd</schemaFiles> - <staleFile>${project.build.directory}/generated-sources/jaxb/org/cytoscape/psi_mi/internal/schema/mi1/.staleFlag</staleFile> - <clearOutputDir>false</clearOutputDir> - </configuration> - <goals> - <goal>xjc</goal> - </goals> - </execution> - <execution> - <id>mi25</id> - <configuration> - <arguments>-nv</arguments> - <packageName>org.cytoscape.psi_mi.internal.schema.mi25</packageName> - <schemaFiles>MIF25.xsd</schemaFiles> - <staleFile>${project.build.directory}/generated-sources/jaxb/org/cytoscape/psi_mi/internal/schema/mi25/.staleFlag</staleFile> - <clearOutputDir>false</clearOutputDir> - </configuration> - <goals> - <goal>xjc</goal> - </goals> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>xerces</groupId> - <artifactId>xercesImpl</artifactId> - <version>2.8.1</version> - </dependency> - </dependencies> - </plugin> - <plugin> - <groupId>org.ops4j</groupId> - <artifactId>maven-pax-plugin</artifactId> - <version>1.4</version> - <extensions>true</extensions> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <version>1.4.3</version> - <configuration> - <instructions> - <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName> - <Bundle-Version>${pom.version}</Bundle-Version> - <_include>-osgi.bnd</_include> - </instructions> - </configuration> - </plugin> - </plugins> - </build> + </plugin> + <plugin> + <groupId>org.ops4j</groupId> + <artifactId>maven-pax-plugin</artifactId> + <version>1.4</version> + <extensions>true</extensions> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>1.4.3</version> + <configuration> + <instructions> + <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName> + <Bundle-Version>${pom.version}</Bundle-Version> + <_include>-osgi.bnd</_include> + </instructions> + </configuration> + </plugin> + </plugins> + </build> </project> Modified: core3/psi-mi-impl/trunk/src/main/java/org/cytoscape/psi_mi/internal/cyto_mapper/MapToCytoscape.java =================================================================== --- core3/psi-mi-impl/trunk/src/main/java/org/cytoscape/psi_mi/internal/cyto_mapper/MapToCytoscape.java 2010-12-09 22:19:39 UTC (rev 23153) +++ core3/psi-mi-impl/trunk/src/main/java/org/cytoscape/psi_mi/internal/cyto_mapper/MapToCytoscape.java 2010-12-09 22:19:56 UTC (rev 23154) @@ -1,13 +1,6 @@ /* - Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org) + Copyright (c) 2006, 2010, 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,6 +27,7 @@ */ package org.cytoscape.psi_mi.internal.cyto_mapper; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -452,8 +446,8 @@ * Creates Edge Between Node1 and Node2. */ private void createEdge(Interactor interactor1, Interactor interactor2, - Interaction interaction, Map<String, CyNode> nodeMap, Set<String> edgeIds) { - + Interaction interaction, Map<String, CyNode> nodeMap, Set<String> edgeIds) + { String name1 = interactor1.getName(); String name2 = interactor2.getName(); @@ -520,9 +514,8 @@ for (Entry<String, Object> entry : attributeMap.entrySet()) { Object value = entry.getValue(); // TODO: Review this: The original code assumed all attributes were Strings - if (value instanceof String) { + if (value instanceof String) addAttribute(attributes, entry.getKey(), value); - } } // Map All External References @@ -538,13 +531,11 @@ idsList.add(ref.getId()); } - if ((dbsList != null) && (dbsList.size() != 0)) { - addAttribute(attributes, CommonVocab.XREF_DB_NAME, dbsList); - } + if ((dbsList != null) && (dbsList.size() != 0)) + addListAttribute(attributes, CommonVocab.XREF_DB_NAME, dbsList, String.class); - if ((idsList != null) && (idsList.size() != 0)) { - addAttribute(attributes, CommonVocab.XREF_DB_ID, idsList); - } + if ((idsList != null) && (idsList.size() != 0)) + addListAttribute(attributes, CommonVocab.XREF_DB_ID, idsList, String.class); } } @@ -565,25 +556,20 @@ if (attrObject instanceof String) { String object; - if (!attributes.isSet(key, String.class)) { + if (!attribExists(attributes, key)) { attributes.getDataTable().createColumn(key, String.class); object = null; - } else { + } else object = attributes.get(key, String.class); - } - String str = (String) attrObject; + String str = (String) attrObject; if (object != null) { String[] values = AttributeUtil.appendString(object, str); - if ((values != null) && (values.toString().length() != 0)) { + if ((values != null) && (values.toString().length() != 0)) attributes.set(key, values.toString()); - } - } else { - if ((str != null) && (str.length() != 0)) { - attributes.set(key, str); - } - } + } else if ((str != null) && (str.length() != 0)) + attributes.set(key, str); } } @@ -600,23 +586,32 @@ idsList.add(ref.getId()); } - if ((dbsList != null) && (dbsList.size() != 0)) { - addAttribute(attributes, CommonVocab.XREF_DB_NAME, dbsList); - } + if ((dbsList != null) && (dbsList.size() != 0)) + addListAttribute(attributes, CommonVocab.XREF_DB_NAME, dbsList, String.class); - if ((idsList != null) && (idsList.size() != 0)) { - addAttribute(attributes, CommonVocab.XREF_DB_ID, idsList); - } + if ((idsList != null) && (idsList.size() != 0)) + addListAttribute(attributes, CommonVocab.XREF_DB_ID, idsList, String.class); } } - private <T> void addAttribute(CyRow attributes, String name, T value) { - if (!attributes.isSet(name, value.getClass())) { + private <T> void addAttribute(final CyRow attributes, final String name, final T value) { + if (!attribExists(attributes, name)) attributes.getDataTable().createColumn(name, value.getClass()); - } attributes.set(name, value); } + private <T> void addListAttribute(final CyRow attributes, final String name, + final List<T> value, final Class<T> listElementType) + { + if (!attribExists(attributes, name)) + attributes.getDataTable().createListColumn(name, listElementType); + attributes.set(name, value); + } + + private boolean attribExists(final CyRow attributes, final String attrName) { + return attributes.getDataTable().getColumnTypeMap().get(attrName) != null; + } + /** * Create Canonical name for Interaction type. * Can be subclassed. Modified: core3/psi-mi-impl/trunk/src/test/java/org/cytoscape/psi_mi/internal/cyto_mapper/MapToCytoscapeTest.java =================================================================== --- core3/psi-mi-impl/trunk/src/test/java/org/cytoscape/psi_mi/internal/cyto_mapper/MapToCytoscapeTest.java 2010-12-09 22:19:39 UTC (rev 23153) +++ core3/psi-mi-impl/trunk/src/test/java/org/cytoscape/psi_mi/internal/cyto_mapper/MapToCytoscapeTest.java 2010-12-09 22:19:56 UTC (rev 23154) @@ -137,15 +137,15 @@ // Verify that DB Names were mapped over correctly. // There are multiple DB Names in an array of Strings. - List<?> dbNameList = nodeAttributes.get(CommonVocab.XREF_DB_NAME, List.class); + List<?> dbNameList = nodeAttributes.getList(CommonVocab.XREF_DB_NAME, String.class); assertEquals(15, dbNameList.size()); assertEquals("RefSeq GI", dbNameList.get(0)); // Verify that Interaction Xrefs were mapped over correctly. CyRow edgeAttributes = edge1.getCyRow(); - dbNameList = edgeAttributes.get(CommonVocab.XREF_DB_NAME, List.class); + dbNameList = edgeAttributes.getList(CommonVocab.XREF_DB_NAME, String.class); - List<?> dbIdList = edgeAttributes.get(CommonVocab.XREF_DB_ID, List.class); + List<?> dbIdList = edgeAttributes.getList(CommonVocab.XREF_DB_ID, String.class); assertEquals(2, dbNameList.size()); assertEquals(2, dbIdList.size()); assertEquals("DIP", dbNameList.get(0)); -- 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.
