Changeset 510

Show
Ignore:
Timestamp:
03/22/11 12:23:13 (14 months ago)
Author:
martijn
Message:

Add support for converting MIRIAM URN to Xref

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/org.bridgedb.bio/test/org/bridgedb/bio/Test.java

    r509 r510  
    130130                assertSame(ds, BioDataSource.ENSEMBL); 
    131131        } 
     132 
     133        @org.junit.Test 
     134        public void testFromUrn() 
     135        { 
     136                Xref ref = Xref.fromUrn("urn:miriam:entrez.gene:3643"); 
     137                assertEquals (BioDataSource.ENTREZ_GENE, ref.getDataSource()); 
     138                assertEquals ("3643", ref.getId()); 
     139 
     140                ref = Xref.fromUrn("urn:miriam:blahblahblah:abc"); 
     141                assertNull (ref); 
     142 
     143                ref = Xref.fromUrn("blahblahblha"); 
     144                assertNull (ref); 
     145                 
     146                ref = Xref.fromUrn("urn:miriam:obo.go:GO%3A00001234"); 
     147                assertEquals (BioDataSource.GENE_ONTOLOGY, ref.getDataSource()); 
     148                assertEquals ("GO:00001234", ref.getId()); 
     149        } 
    132150         
    133151} 
  • trunk/org.bridgedb/src/org/bridgedb/DataSource.java

    r509 r510  
    6060        private static Set<DataSource> registry = new HashSet<DataSource>(); 
    6161        private static Map<String, DataSource> byAlias = new HashMap<String, DataSource>(); 
     62        private static Map<String, DataSource> byMiriamBase = new HashMap<String, DataSource>(); 
    6263         
    6364        private String sysCode = null; 
     
    311312                } 
    312313                 
     314                if (current.urnBase != null) 
     315                { 
     316                        byMiriamBase.put (current.urnBase, current); 
     317                } 
     318                 
    313319                current.sysCode = sysCode; 
    314320                current.fullName = fullName; 
     
    466472        } 
    467473 
     474        public static DataSource getByUrnBase(String base) 
     475        { 
     476                return byMiriamBase.get(base); 
     477        } 
     478 
    468479} 
  • trunk/org.bridgedb/src/org/bridgedb/Xref.java

    r308 r510  
    1616// 
    1717package org.bridgedb; 
     18 
     19import java.io.UnsupportedEncodingException; 
     20import java.net.URLDecoder; 
    1821 
    1922/** 
     
    109112                return ds.getURN (id); 
    110113        } 
     114         
     115        public static Xref fromUrn(String urn) 
     116        { 
     117                int pos = urn.lastIndexOf(":"); 
     118                if (pos < 0) return null; 
     119                 
     120                String base = urn.substring(0, pos); 
     121                String id; 
     122                try 
     123                { 
     124                        id = URLDecoder.decode(urn.substring(pos + 1), "UTF-8"); 
     125                } 
     126                catch (UnsupportedEncodingException e) 
     127                { 
     128                        return null; 
     129                } 
     130                 
     131                DataSource ds = DataSource.getByUrnBase(base); 
     132                if (ds == null) return null; 
     133                 
     134                return new Xref (id, ds); 
     135        } 
    111136 
    112137}