Author: jgao
Date: 2010-09-03 13:37:11 -0700 (Fri, 03 Sep 2010)
New Revision: 21691
Added:
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceCommandBasedClient.java
Modified:
csplugins/trunk/soc/jgao/IDMappingService/CyThesaurusService.jar
csplugins/trunk/soc/jgao/IDMappingService/build.xml
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceClient.java
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceMessageBasedClient.java
Log:
CyThesaurusService: command based client
Modified: csplugins/trunk/soc/jgao/IDMappingService/CyThesaurusService.jar
===================================================================
(Binary files differ)
Modified: csplugins/trunk/soc/jgao/IDMappingService/build.xml
===================================================================
--- csplugins/trunk/soc/jgao/IDMappingService/build.xml 2010-09-03 20:36:14 UTC
(rev 21690)
+++ csplugins/trunk/soc/jgao/IDMappingService/build.xml 2010-09-03 20:37:11 UTC
(rev 21691)
@@ -10,12 +10,17 @@
<tstamp/>
<property name="src" location="src"/>
<property name="lib" value="lib"/>
+ <property name="cyrelease" location="../cytoscape"/>
<property name="build" location="build"/>
<property name="build.classes" location="${build}/classes"/>
<property name="jar.name" location="CyThesaurusService.jar"/>
<!-- Classpath with all lib JAR Files and all Cytoscape Core classes -->
<path id="classpath">
+ <!-- include cytoscape.jar, which is it release directory top level -->
+ <fileset dir="${cyrelease}">
+ <include name="*.jar"/>
+ </fileset>
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
Modified:
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceClient.java
===================================================================
---
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceClient.java
2010-09-03 20:36:14 UTC (rev 21690)
+++
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceClient.java
2010-09-03 20:37:11 UTC (rev 21691)
@@ -180,4 +180,11 @@
* @return true if the ID exists in the ID type; false, otherwise.
*/
public boolean idExists(String id, String type);
+
+ /**
+ * Guess the types of sample source ids
+ * @param ids sample ids
+ * @return a set of types that match the ids
+ */
+ public Set<String> guessType(Set<String> ids);
}
Added:
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceCommandBasedClient.java
===================================================================
---
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceCommandBasedClient.java
(rev 0)
+++
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceCommandBasedClient.java
2010-09-03 20:37:11 UTC (rev 21691)
@@ -0,0 +1,313 @@
+/*
+ Copyright (c) 2006, 2007, 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
+ 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 cytoscape.cythesaurus.service;
+
+import cytoscape.command.CyCommandException;
+import cytoscape.command.CyCommandManager;
+import cytoscape.command.CyCommandResult;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+
+/**
+ *
+ * @author gjj
+ */
+public class CyThesaurusServiceCommandBasedClient
+ implements CyThesaurusServiceClient{
+
+ private final String NAMESPACE = "idmapping";
+
+ // Commands
+ private static final String VERSION = "version";
+ private static final String MAIN_DIALOG = "main dialog";
+ private static final String RESOURCE_DIALOG = "resource config dialog";
+ private static final String LIST_RESOURCE = "list resources";
+ private static final String LIST_SELECTED_RESOURCE = "list selected
resources";
+ private static final String ADD_RESOURCE = "register resource";
+ private static final String REMOVE_RESOURCE = "unregister resource";
+ private static final String SELECT_RESOURCE = "select resource";
+ private static final String DESELECT_RESOURCE = "deselect resource";
+ private static final String GET_SRC_ID_TYPES = "get source id types";
+ private static final String GET_TGT_ID_TYPES = "get target id types";
+ private static final String CHECK_MAPPING_SUPPORT = "check mapping
supported";
+ private static final String ATTRIBUTE_BASED_MAPPING = "attribute based
mapping";
+ private static final String GENERAL_MAPPING = "general mapping";
+ private static final String CHECK_ID_EXIST = "check id exist";
+ private static final String GUESS_TYPE = "guess id type";
+
+ // Arguments
+ private static final String CLASS_PATH = "classpath";
+ private static final String CONN_STRING = "connstring"; // connection
string
+ private static final String DISPLAY_NAME = "displayname";
+ private static final String SOURCE_TYPE = "sourcetype";
+ private static final String TARGET_TYPE = "targettype";
+ private static final String NETWORK_LIST = "networklist";
+ private static final String SOURCE_ATTR = "sourceattr";
+ private static final String TARGET_ATTR = "targetattr";
+ private static final String SOURCE_ID = "sourceid";
+ private static final String REPORT = "report";
+
+ public CyThesaurusServiceCommandBasedClient() {
+
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public boolean isServiceAvailable() {
+ List<String> cmds = CyCommandManager.getCommandList(NAMESPACE);
+ return cmds!=null && !cmds.isEmpty();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public double serviceVersion() {
+ CyCommandResult result = executeCommand(VERSION, null);
+ if (result==null || !result.successful())
+ return -1.0;
+
+ return (Double)result.getResult();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public boolean openAttributeConfigDialog() {
+ CyCommandResult result = executeCommand(MAIN_DIALOG, null);
+ if (result==null || !result.successful())
+ return false;
+
+ return (Boolean)result.getResult();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public boolean openMappingResourceConfigDialog() {
+ CyCommandResult result = executeCommand(RESOURCE_DIALOG, null);
+ if (result==null || !result.successful())
+ return false;
+
+ return (Boolean)result.getResult();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public Set<String> allIDMappers() {
+ CyCommandResult result = executeCommand(LIST_RESOURCE, null);
+ if (result==null || !result.successful())
+ return Collections.emptySet();
+
+ return (Set<String>)result.getResult();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public Set<String> selectedIDMappers() {
+ CyCommandResult result = executeCommand(LIST_SELECTED_RESOURCE, null);
+ if (result==null || !result.successful())
+ return Collections.emptySet();
+
+ return (Set<String>)result.getResult();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public boolean registerIDMapper(String connectionString, String classPath,
String displayName) {
+ Map<String,Object> args = new HashMap<String,Object>(3);
+ args.put(CONN_STRING, connectionString);
+ args.put(CLASS_PATH, classPath);
+ args.put(DISPLAY_NAME, displayName);
+ CyCommandResult result = executeCommand(ADD_RESOURCE, args);
+ return result!=null && result.successful();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public boolean unregisterIDMapper(String connectionString) {
+ Map<String,Object> args = new HashMap<String,Object>(1);
+ args.put(CONN_STRING, connectionString);
+ CyCommandResult result = executeCommand(REMOVE_RESOURCE, args);
+ return result!=null && result.successful();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public boolean setIDMapperSelect(String connectionString, boolean
selected) {
+ Map<String,Object> args = new HashMap<String,Object>(1);
+ args.put(CONN_STRING, connectionString);
+ CyCommandResult result;
+ if (selected) {
+ result = executeCommand(SELECT_RESOURCE, args);
+ } else {
+ result = executeCommand(DESELECT_RESOURCE, args);
+ }
+ return result!=null && result.successful();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public Set<String> supportedSrcIDTypes() {
+ CyCommandResult result = executeCommand(GET_SRC_ID_TYPES, null);
+ if (result==null || !result.successful())
+ return Collections.emptySet();
+
+ return (Set<String>)result.getResult();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public Set<String> supportedTgtIDTypes() {
+ CyCommandResult result = executeCommand(GET_TGT_ID_TYPES, null);
+ if (result==null || !result.successful())
+ return Collections.emptySet();
+
+ return (Set<String>)result.getResult();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public boolean isMappingSupported(String srcType, String tgtType) {
+ Map<String,Object> args = new HashMap<String,Object>(2);
+ args.put(SOURCE_TYPE, srcType);
+ args.put(TARGET_TYPE, tgtType);
+ CyCommandResult result = executeCommand(CHECK_MAPPING_SUPPORT, args);
+ return result!=null && result.successful();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public boolean mapID(Set<String> netIds, String srcAttrName,
+ String tgtAttrName, Set<String> srcIDTypes, String tgtIDType) {
+ Map<String,Object> args = new HashMap<String,Object>(5);
+ args.put(NETWORK_LIST, netIds);
+ args.put(SOURCE_ATTR, srcAttrName);
+ args.put(TARGET_ATTR, tgtAttrName);
+ args.put(SOURCE_TYPE, srcIDTypes);
+ args.put(TARGET_TYPE, tgtIDType);
+ CyCommandResult result = executeCommand(ATTRIBUTE_BASED_MAPPING, args);
+ return result!=null && result.successful();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public Map<String,String> mapID(Set<String> netIds, String srcAttrName,
+ Set<String> srcIDTypes, Set<String> tgtIDTypes) {
+ Map<String,String> mapTgtTypeAttr = new
HashMap<String,String>(tgtIDTypes.size());
+ for (String tgtType : tgtIDTypes) {
+ Map<String,Object> args = new HashMap<String,Object>(5);
+ args.put(NETWORK_LIST, netIds);
+ args.put(SOURCE_ATTR, srcAttrName);
+// args.put(TARGET_ATTR, null);
+ args.put(SOURCE_TYPE, srcIDTypes);
+ args.put(TARGET_TYPE, tgtType);
+ CyCommandResult result = executeCommand(ATTRIBUTE_BASED_MAPPING,
args);
+ if (result==null || !result.successful()) {
+ continue; // TODO: how to deal?
+ }
+
+ mapTgtTypeAttr.put(tgtType, result.getStringResult(TARGET_ATTR));
+ }
+
+ return mapTgtTypeAttr;
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public Map<String, Set<String>> mapID(Set<String> srcIDs, String srcIDType,
+ String tgtIDType) {
+ Map<String,Object> args = new HashMap<String,Object>(3);
+ args.put(SOURCE_ID, srcIDs);
+ args.put(SOURCE_TYPE, srcIDType);
+ args.put(TARGET_TYPE, tgtIDType);
+ CyCommandResult result = executeCommand(GENERAL_MAPPING, args);
+ if (result==null || !result.successful()) {
+ return Collections.emptyMap();
+ }
+ return (Map<String, Set<String>>)result.getResult();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public boolean idExists(String id, String type) {
+ Map<String,Object> args = new HashMap<String,Object>(2);
+ args.put(SOURCE_ID, id);
+ args.put(SOURCE_TYPE, type);
+ CyCommandResult result = executeCommand(CHECK_ID_EXIST, args);
+ return result!=null && result.successful();
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ public Set<String> guessType(Set<String> ids) {
+ Map<String,Object> args = new HashMap<String,Object>(1);
+ args.put(SOURCE_ID, ids);
+ CyCommandResult result = executeCommand(GUESS_TYPE, args);
+ if (result==null || !result.successful()) {
+ return Collections.emptySet();
+ }
+ return (Set<String>)result.getResult();
+ }
+
+ private CyCommandResult executeCommand(String command, Map<String,Object>
args) {
+ CyCommandResult result = null;
+ try {
+ result = CyCommandManager.execute(NAMESPACE, command, args);
+ } catch (CyCommandException e) {
+ }
+
+ return result;
+ }
+}
Modified:
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceMessageBasedClient.java
===================================================================
---
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceMessageBasedClient.java
2010-09-03 20:36:14 UTC (rev 21690)
+++
csplugins/trunk/soc/jgao/IDMappingService/src/cytoscape/cythesaurus/service/CyThesaurusServiceMessageBasedClient.java
2010-09-03 20:37:11 UTC (rev 21691)
@@ -66,6 +66,7 @@
private final String MSG_TYPE_REQUEST_UNREGISTER_MAPPER =
"UNREGISTER_ID_MAPPER";
private final String MSG_TYPE_REQUEST_SELECT_MAPPER = "SELECT_ID_MAPPER";;
private final String MSG_TYPE_REQUEST_ID_EXIST = "ID_EXIST";
+ private final String MSG_TYPE_REQUEST_GUESS_TYPE = "GUESSING_TYPE";
private final String VERSION = "VERSION";
private final String NETWORK_ID = "NETWORK_ID";
@@ -163,7 +164,20 @@
for (ResponseMessage response : responses) {
if (response.getSender().compareTo(receiver)==0) {
- return true;
+ Object obj = response.getContent();
+ if (obj instanceof Map) {
+ Map content = (Map) obj;
+ obj = content.get(SUCCESS);
+ if (obj instanceof Boolean) {
+ boolean succ = (Boolean) obj;
+ if (succ) {
+ obj = content.get(IS_CANCELLED);
+ if (obj instanceof Boolean) {
+ return !((Boolean) obj);
+ }
+ }
+ }
+ }
}
}
@@ -630,4 +644,42 @@
return false;
}
+
+ /**
+ * {...@inheritdoc}
+ */
+ public Set<String> guessType(Set<String> ids) {
+ if (ids==null) {
+ throw new IllegalArgumentException();
+ }
+
+ String receiver = CYTHESAURUS;
+ String msgType = MSG_TYPE_REQUEST_GUESS_TYPE;
+ String msgId = requester+receiver+msgType+ System.currentTimeMillis();
+ Map map = new HashMap();
+ map.put(SOURCE_ID, ids);
+ Message msg = new Message(msgId , requester, receiver, msgType , map);
+ List<ResponseMessage> responses =
PluginsCommunicationSupport.sendMessageAndGetResponses(msg);
+
+ for (ResponseMessage response : responses) {
+ if (response.getSender().compareTo(receiver)==0) {
+ Object obj = response.getContent();
+ if (obj instanceof Map) {
+ Map content = (Map) obj;
+ obj = content.get(SUCCESS);
+ if (obj instanceof Boolean) {
+ boolean succ = (Boolean) obj;
+ if (succ) {
+ obj = content.get(SOURCE_ID_TYPE);
+ if (obj instanceof Set) {
+ return (Set) obj;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
}
--
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.