Changeset 513 for trunk

Show
Ignore:
Timestamp:
05/09/11 12:09:58 (13 months ago)
Author:
martijn
Message:

Improvements to server config file: allow comments, allow specification of extra driver classes

Location:
trunk
Files:
2 added
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/org.bridgedb.bio/resources/org/bridgedb/bio/datasources.xml

    r509 r513  
    1 <datasources> 
    2         <datasource fullname="Ensembl"> 
    3                 <alias name="ensembl_gene_id"/> 
    4         </datasource> 
    5         <datasource fullname="Entrez Gene"> 
    6                 <alias name="entrezgene"/> 
    7         </datasource> 
    8         <datasource fullname="Affy"> 
    9                 <alias name="affy_hg_u133a_2"/> 
    10         </datasource> 
    11 </datasources> 
     1<?xml version="1.0"?> 
     2<bridgedb> 
     3        <datasources> 
     4                <datasource fullname="Ensembl"> 
     5                        <alias name="ensembl_gene_id"/> 
     6                </datasource> 
     7                <datasource fullname="Entrez Gene"> 
     8                        <alias name="entrezgene"/> 
     9                </datasource> 
     10                <datasource fullname="Affy"> 
     11                        <alias name="affy_hg_u133a_2"/> 
     12                </datasource> 
     13        </datasources> 
     14        <properties> 
     15                <property key="org.bridgedb.webservice.synergizer.DefaultUrl" value="http://...."/> 
     16        </properties> 
     17</bridgedb> 
  • trunk/org.bridgedb.rdb/src/org/bridgedb/rdb/GdbProvider.java

    r506 r513  
    3232import org.bridgedb.IDMapperStack; 
    3333import org.bridgedb.bio.Organism; 
     34import org.bridgedb.rdb.impl.ConfigFile; 
    3435 
    3536/** 
     
    107108        } 
    108109         
    109         public static GdbProvider fromConfigFile(File f, boolean transitive) throws IDMapperException, IOException, ClassNotFoundException { 
    110                 System.out.println("Parsing gene database configuration: " + f.getAbsolutePath()); 
     110        public static GdbProvider fromConfigFile(File f, boolean transitive) throws IDMapperException, IOException, ClassNotFoundException  
     111        {        
     112                ConfigFile cf = new ConfigFile(f);       
    111113                GdbProvider gdbs = new GdbProvider(transitive); 
    112                 BufferedReader in = new BufferedReader(new FileReader(f)); 
    113                 String line = in.readLine(); 
    114                 Class.forName ("org.bridgedb.rdb.IDMapperRdb"); 
    115                 Class.forName("org.bridgedb.file.IDMapperText"); 
    116                 try 
     114                List<String> drivers = cf.getDrivers(); 
     115                 
     116                // add a few defaults that will always be loaded 
     117                drivers.add("org.bridgedb.rdb.IDMapperRdb"); 
     118                drivers.add("org.bridgedb.file.IDMapperText"); 
     119                drivers.add("com.mysql.jdbc.Driver"); 
     120                 
     121                for (String driver : drivers) 
    117122                { 
    118                         Class.forName ("com.mysql.jdbc.Driver"); 
     123                        try 
     124                        { 
     125                                Class.forName (driver); 
     126                                System.out.println ("Loaded driver: " + driver); 
     127                        } 
     128                        catch (ClassNotFoundException ex) 
     129                        { 
     130                                System.out.println ("Warning: driver '" + driver + "'  not in classpath, some features may not be available."); 
     131                        } 
    119132                } 
    120                 catch (ClassNotFoundException ex) 
     133 
     134                for (String key : cf.getMappers().keySet()) 
    121135                { 
    122                         System.out.println ("MySQL driver not in classpath, mysql backend unavailable"); 
    123                 } 
    124                 while(line != null) { 
    125                         String[] kv = line.split("\t"); 
    126                         if(kv.length == 2) { 
    127                                 String key = kv[0]; 
    128                                 String value = kv[1]; 
    129                                  
    130                                 if (!value.startsWith("idmapper")) value = "idmapper-pgdb:" + value; 
     136                        for (String value : cf.getMappers().get(key)) 
     137                        { 
    131138                                IDMapper mapper = BridgeDb.connect (value); 
    132139                                Organism org = Organism.fromLatinName(key); 
     
    138145                                        System.out.println("Unable to parse organism: " + key); 
    139146                                } 
    140                         } else { 
    141                                 System.out.println("Invalid key/value pair in gene database configuration: " + line); 
    142147                        } 
    143                         line = in.readLine(); 
    144148                } 
    145                 in.close(); 
     149 
    146150                return gdbs; 
    147151        } 
  • trunk/org.bridgedb/src/org/bridgedb/impl/InternalUtils.java

    r509 r513  
    2121import java.net.URL; 
    2222import java.net.URLConnection; 
     23import java.util.ArrayList; 
    2324import java.util.Arrays; 
    2425import java.util.Collection; 
     
    2627import java.util.HashMap; 
    2728import java.util.HashSet; 
     29import java.util.List; 
    2830import java.util.Map; 
    2931import java.util.Set; 
     
    229231     * will not be discared. 
    230232     * <p> 
     233     * This is like multiMapPut, but uses a list instead of a set for each value of the map.  
     234     * @param <T> key type of multimap 
     235     * @param <U> value type of multimap 
     236     * @param map multimap to work on 
     237     * @param key key of the value to insert 
     238     * @param val value to insert. 
     239    */ 
     240    public static <T, U> void multiMapAdd(Map<T, List<U>> map, T key, U val) 
     241    { 
     242        List<U> list; 
     243        if (map.containsKey (key)) 
     244        { 
     245                list = map.get(key); 
     246        } 
     247        else 
     248        { 
     249                list = new ArrayList<U>(); 
     250                map.put(key, list); 
     251        } 
     252        list.add (val); 
     253    } 
     254 
     255    /** 
     256     * Generic method for multimaps, a map that can contain multiple values per key. 
     257     * Unlike a regular map, if you insert a value for a key that already exists, the previous value  
     258     * will not be discared. 
     259     * <p> 
    231260     * multiMapPutAll let's you insert a collection of items at once.  
    232261     * @param <T> key type of multimap