Author: jgao
Date: 2010-09-10 14:20:04 -0700 (Fri, 10 Sep 2010)
New Revision: 21799

Added:
   
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/util/BridgeRestUtil.java
Modified:
   
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/CyThesaurusPlugin.java
   
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/FinalStaticValues.java
   
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/IDMapperClientManager.java
   
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
   
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.form
   
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.java
Log:
CyThesaurus: forbid saving target ids into existing attribute; set default 
resource

Modified: 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/CyThesaurusPlugin.java
===================================================================
--- 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/CyThesaurusPlugin.java
  2010-09-10 20:31:35 UTC (rev 21798)
+++ 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/CyThesaurusPlugin.java
  2010-09-10 21:20:04 UTC (rev 21799)
@@ -65,7 +65,8 @@
     public CyThesaurusPlugin() {
         try {
             BioDataSource.init();
-            IDMapperClientManager.reloadFromCytoscapeGlobalProperties();
+//            IDMapperClientManager.reloadFromCytoscapeGlobalProperties();
+            registerDefaultClients();
             listenToSessionEvent();
 
             IDMappingServiceSuppport.addService();
@@ -84,8 +85,8 @@
         pcs.addPropertyChangeListener(Cytoscape.CYTOSCAPE_INITIALIZED,
                 new PropertyChangeListener() {
             public void propertyChange(PropertyChangeEvent evt) {
-                IDMapperClientManager.reloadFromCytoscapeGlobalProperties();
-
+//                IDMapperClientManager.reloadFromCytoscapeGlobalProperties();
+                registerDefaultClients();
                 mapSrcAttrIDTypes = null;
             }
         });
@@ -112,7 +113,8 @@
 
                 if (IDMapperClientManager.countClients()==0) {
                     // load the default clients if no client
-                    
IDMapperClientManager.reloadFromCytoscapeGlobalProperties();
+//                    
IDMapperClientManager.reloadFromCytoscapeGlobalProperties();
+                    registerDefaultClients();
                 }
 
                 mapSrcAttrIDTypes = null;
@@ -120,6 +122,13 @@
         });
     }
 
+    private void registerDefaultClients() {
+        IDMapperClientManager.reloadFromCytoscapeGlobalProperties();
+        if (IDMapperClientManager.countClients()==0) {
+            IDMapperClientManager.registerDefaultClient();
+        }
+    }
+
     class IDMappingAction extends CytoscapeAction {
 
         public IDMappingAction() {

Modified: 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/FinalStaticValues.java
===================================================================
--- 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/FinalStaticValues.java
  2010-09-10 20:31:35 UTC (rev 21798)
+++ 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/FinalStaticValues.java
  2010-09-10 21:20:04 UTC (rev 21799)
@@ -43,5 +43,5 @@
     public static final String PLUGIN_NAME = "CyThesaurus";
     public static final String CLIENT_GLOBAL_PROPS = 
"cythesaurus.clients.props";
     public static final String CLIENT_SESSION_PROPS = "cythesaurus.client";
-
+    public static final String DEFAULT_SPECIES_NAME = "defaultSpeciesName";
 }

Modified: 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/IDMapperClientManager.java
===================================================================
--- 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/IDMapperClientManager.java
      2010-09-10 20:31:35 UTC (rev 21798)
+++ 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/IDMapperClientManager.java
      2010-09-10 21:20:04 UTC (rev 21799)
@@ -35,6 +35,8 @@
 
 package csplugins.id.mapping;
 
+import csplugins.id.mapping.util.BridgeRestUtil;
+
 import cytoscape.CytoscapeInit;
 
 import java.io.BufferedReader;
@@ -47,14 +49,12 @@
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 
-import org.bridgedb.DataSource;
 import org.bridgedb.IDMapper;
-import org.bridgedb.IDMapperCapabilities;
-import org.bridgedb.IDMapperException;
 import org.bridgedb.IDMapperStack;
 
 /**
@@ -66,11 +66,11 @@
     private static Map<String, IDMapperClient> clientConnectionStringMap;
 
     static {
-        new IDMapperClientManager();
+//        new IDMapperClientManager();
+        clientConnectionStringMap = new HashMap();
     }
 
     private IDMapperClientManager() {
-        clientConnectionStringMap = new HashMap();
         //reloadFromCytoscapeSessionProperties();
     }
 
@@ -187,6 +187,33 @@
         return true;
     }
 
+    static boolean registerDefaultClient() {
+        Properties props = CytoscapeInit.getProperties();
+        String defaultSpecies = 
props.getProperty(FinalStaticValues.DEFAULT_SPECIES_NAME);
+
+        List<String> orgs = 
BridgeRestUtil.supportedOrganisms(BridgeRestUtil.defaultBaseUrl);
+        if (!orgs.contains(defaultSpecies))
+            return false;
+
+        String classPath = "org.bridgedb.webservice.bridgerest.BridgeRest";
+        String connStr = 
"idmapper-bridgerest:"+BridgeRestUtil.defaultBaseUrl+"/"+defaultSpecies;
+        IDMapperClient client;
+        try {
+            client = new IDMapperClientImplTunables
+                                .Builder(connStr, classPath)
+                                
.displayName("BridgeDb("+BridgeRestUtil.defaultBaseUrl+"/"+defaultSpecies+")")
+                                .selected(true)
+                                
.clientType(IDMapperClient.ClientType.WEBSERVICE)
+                                .build();
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+
+        registerClient(client);
+        return true;
+    }
+
     public static void saveCurrentToCytoscapeGlobalProperties() throws 
IOException {
         String fileName = FinalStaticValues.CLIENT_GLOBAL_PROPS;
         File file = cytoscape.CytoscapeInit.getConfigFile(fileName);

Modified: 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
===================================================================
--- 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
       2010-09-10 20:31:35 UTC (rev 21798)
+++ 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
       2010-09-10 21:20:04 UTC (rev 21799)
@@ -487,10 +487,10 @@
                 throw new CyCommandException(NETWORK_LIST+" must be String or 
Collection<String> "
                         + "or CyNetwork or Collection<CyNetwork>.\n");
             }
+        }
 
-            if (networks.isEmpty()) {
-                throw new CyCommandException("No network to work on.");
-            }
+        if (networks.isEmpty()) {
+            throw new CyCommandException("No network to work on.");
         }
 
         Set<String> attributes = new HashSet();
@@ -505,26 +505,24 @@
         }else{
             if (obj instanceof String) {
                 String attr = (String)obj;
-                if (attributes.contains(attr)) {
-                    srcAttrs.add(attr);
-                } else {
+                if (!attributes.contains(attr)) {
                     throw new CyCommandException("Node attribute "+attr+" does 
not exist.");
                 }
+                srcAttrs.add(attr);
             } else if (obj instanceof Collection) {
                 Collection<String> attrs = (Collection)obj;
                 for (String attr : attrs) {
                     if (attributes.contains(attr)) {
-                        srcAttrs.add(attr);
-                    } else {
                         throw new CyCommandException("Node attribute "+attr+" 
does not exist.");
                     }
+                    srcAttrs.add(attr);
                 }
             } else {
                 throw new CyCommandException(SOURCE_ATTR+" must be String or 
Collection<String>.\n");
             }
 
             if (srcAttrs.isEmpty()) {
-                throw new CyCommandException("No network to work on.");
+                throw new CyCommandException("No source attribute to work 
on.");
             }
         }
 
@@ -602,18 +600,20 @@
 
         String tgtAttr = getArg(command, TARGET_ATTR, args);
         if (tgtAttr==null) {
-            Set<String> usedName = new HashSet();
-            usedName.add("ID"); //TODO remove in Cy3
-            
usedName.addAll(java.util.Arrays.asList(Cytoscape.getNodeAttributes().getAttributeNames()));
-            if (usedName.contains(tgtType)) {
+            if (attributes.contains(tgtType)) {
                 int num = 1;
-                while (usedName.contains(tgtType+"."+num)) {
+                while (attributes.contains(tgtType+"."+num)) {
                     num ++;
                 }
                 tgtAttr = tgtType+"."+num;
             } else {
                 tgtAttr = tgtType;
             }
+        } else {
+            if (attributes.contains(tgtAttr)) {
+                throw new CyCommandException(tgtAttr+" is an existing 
attribute "
+                        + "and hence cannot be used as target attribute 
name.");
+            }
         }
 
         obj = args.get(FIRST_ONLY);

Modified: 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.form
===================================================================
--- 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.form
   2010-09-10 20:31:35 UTC (rev 21798)
+++ 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.form
   2010-09-10 21:20:04 UTC (rev 21799)
@@ -102,7 +102,7 @@
               </Properties>
               <AuxValues>
                 <AuxValue name="JavaCodeGenerator_DeclarationPost" 
type="java.lang.String" value="private TextComboBoxEditor 
bridgedbComboBoxEditor;"/>
-                <AuxValue name="JavaCodeGenerator_InitCodePre" 
type="java.lang.String" value="DefaultComboBoxModel bridgeComboBoxModel = new 
DefaultComboBoxModel();&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Arabidopsis
 
thaliana&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Bacillus
 
subtilis&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Caenorhabditis
 
elegans&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Chicken&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Cow&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Danio
 
rerio&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Dog&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Escherichia
 
coli&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Frui!
 t 
fly&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Horse&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Mouse&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Human&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Mosquito&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Populus
 
trichocarpa&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Rat&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Rice&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Saccharomyces
 
cerevisiae&quot;);&#xa;bridgeComboBoxModel.addElement(&quot;http://webservice.bridgedb.org/Xenopus
 
tropicalis&quot;);&#xa;bridgedbBaseUrlComboBox.setModel(bridgeComboBoxModel);&#xa;bridgedbComboBoxEditor
 = new TextComboBoxEditor(&quot;http://webservice.bridgedb.org/Human&;!
 quot;);&#xa;bridgedbBaseUrlComboBox.setEditor(bridgedbComboBox!
 Editor);
&#xa;bridgedbBaseUrlComboBox.setSelectedItem(&quot;http://webservice.bridgedb.org/Human&quot;);"/>
+                <AuxValue name="JavaCodeGenerator_InitCodePre" 
type="java.lang.String" value="List&lt;String&gt; orgs = 
BridgeRestUtil.supportedOrganismsNr(BridgeRestUtil.defaultBaseUrl);&#xa;String[]
 orgUrls = new String[orgs.size()];&#xa;int iorg = 0;&#xa;for (String org : 
orgs) {&#xa;    orgUrls[iorg++] = BridgeRestUtil.defaultBaseUrl + &quot;/&quot; 
+org;&#xa;}&#xa;DefaultComboBoxModel bridgeComboBoxModel = new 
DefaultComboBoxModel(orgUrls);&#xa;bridgedbBaseUrlComboBox.setModel(bridgeComboBoxModel);&#xa;String
 textInEditor = orgUrls.length==0?&quot;No organism available, please specify 
yours.&quot;:orgUrls[0];&#xa;bridgedbComboBoxEditor = new 
TextComboBoxEditor(textInEditor);&#xa;bridgedbBaseUrlComboBox.setEditor(bridgedbComboBoxEditor);&#xa;//bridgedbBaseUrlComboBox.setSelectedItem(&quot;http://webservice.bridgedb.org/Human&quot;);"/>
               </AuxValues>
               <Constraints>
                 <Constraint 
layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" 
value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">

Modified: 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.java
===================================================================
--- 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.java
   2010-09-10 20:31:35 UTC (rev 21798)
+++ 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.java
   2010-09-10 21:20:04 UTC (rev 21799)
@@ -37,6 +37,7 @@
 
 import csplugins.id.mapping.IDMapperClient;
 import csplugins.id.mapping.IDMapperClientImplTunables;
+import csplugins.id.mapping.util.BridgeRestUtil;
 
 import cytoscape.task.Task;
 import cytoscape.task.TaskMonitor;
@@ -49,6 +50,7 @@
 import org.bridgedb.webservice.biomart.BiomartStub;
 import org.bridgedb.webservice.synergizer.SynergizerStub;
 
+import java.util.List;
 import java.util.Set;
 import java.util.HashSet;
 import java.util.Vector;
@@ -237,29 +239,18 @@
         
bridgedbBaseUrlPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Base
 URL of BridgeDb web service"));
         bridgedbBaseUrlPanel.setLayout(new java.awt.GridBagLayout());
 
-        DefaultComboBoxModel bridgeComboBoxModel = new DefaultComboBoxModel();
-        
bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Arabidopsis 
thaliana");
-        
bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Bacillus 
subtilis");
-        
bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Caenorhabditis 
elegans");
-        
bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Chicken";);
-        bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Cow";);
-        bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Danio 
rerio");
-        bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Dog";);
-        
bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Escherichia 
coli");
-        bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Fruit 
fly");
-        bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Horse";);
-        bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Mouse";);
-        bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Human";);
-        
bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Mosquito";);
-        bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Populus 
trichocarpa");
-        bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Rat";);
-        bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Rice";);
-        
bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Saccharomyces 
cerevisiae");
-        bridgeComboBoxModel.addElement("http://webservice.bridgedb.org/Xenopus 
tropicalis");
+        List<String> orgs = 
BridgeRestUtil.supportedOrganismsNr(BridgeRestUtil.defaultBaseUrl);
+        String[] orgUrls = new String[orgs.size()];
+        int iorg = 0;
+        for (String org : orgs) {
+            orgUrls[iorg++] = BridgeRestUtil.defaultBaseUrl + "/" +org;
+        }
+        DefaultComboBoxModel bridgeComboBoxModel = new 
DefaultComboBoxModel(orgUrls);
         bridgedbBaseUrlComboBox.setModel(bridgeComboBoxModel);
-        bridgedbComboBoxEditor = new 
TextComboBoxEditor("http://webservice.bridgedb.org/Human";);
+        String textInEditor = orgUrls.length==0?"No organism available, please 
specify yours.":orgUrls[0];
+        bridgedbComboBoxEditor = new TextComboBoxEditor(textInEditor);
         bridgedbBaseUrlComboBox.setEditor(bridgedbComboBoxEditor);
-        
bridgedbBaseUrlComboBox.setSelectedItem("http://webservice.bridgedb.org/Human";);
+        
//bridgedbBaseUrlComboBox.setSelectedItem("http://webservice.bridgedb.org/Human";);
         bridgedbBaseUrlComboBox.setEditable(true);
         gridBagConstraints = new java.awt.GridBagConstraints();
         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;

Added: 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/util/BridgeRestUtil.java
===================================================================
--- 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/util/BridgeRestUtil.java
                                (rev 0)
+++ 
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/util/BridgeRestUtil.java
        2010-09-10 21:20:04 UTC (rev 21799)
@@ -0,0 +1,107 @@
+/*
+ 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 csplugins.id.mapping.util;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import java.net.URL;
+import java.net.URLConnection;
+
+
+/**
+ *
+ * @author gjj
+ */
+public class BridgeRestUtil {
+    private BridgeRestUtil(){}
+
+    public static String defaultBaseUrl = "http://webservice.bridgedb.org";;
+
+    public static List<String> supportedOrganisms(String baseUrl) {
+        return supportedOrganisms(baseUrl, -1);
+    }
+
+    public static List<String> supportedOrganismsNr(String baseUrl) {
+        return supportedOrganisms(baseUrl, 0);
+    }
+
+    public static List<String> supportedOrganismsLatin(String baseUrl) {
+        return supportedOrganisms(baseUrl, 1);
+    }
+
+    private static List<String> supportedOrganisms(String baseUrl, int column) 
{
+        String contentUrl = baseUrl + "/contents";
+        List<String> lines;
+        try {
+            lines = readUrl(contentUrl);
+        } catch (IOException e) {
+            e.printStackTrace();
+            return Collections.emptyList();
+        }
+
+        List<String> ret = new ArrayList<String>(lines.size());
+        for (String line : lines) {
+            String[] strs = line.split("\t");
+            if (column>=0)
+                ret.add(strs[strs.length>column?column:0]);
+            else
+                ret.addAll(Arrays.asList(strs));
+        }
+        return ret;
+    }
+
+    private static List<String> readUrl(String strUrl) throws IOException {
+        URL url = new URL(strUrl);
+        URLConnection yc = url.openConnection();
+        BufferedReader in = new BufferedReader(
+                                new InputStreamReader(
+                                yc.getInputStream()));
+        List<String> ret = new ArrayList<String>();
+        String inputLine;
+        while ((inputLine = in.readLine()) != null)
+            ret.add(inputLine);
+        in.close();
+
+        return ret;
+    }
+}

-- 
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.

Reply via email to