Skip to content

Commit

Permalink
Add support for converting MIRIAM URN to Xref
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.bigcat.unimaas.nl/bridgedb/trunk@510 e3f1d335-44b1-4163-9530-9b341189ae98
  • Loading branch information
martijn committed Mar 22, 2011
1 parent 8308db0 commit 414fd74
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
18 changes: 18 additions & 0 deletions org.bridgedb.bio/test/org/bridgedb/bio/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,23 @@ public void testAlias()
DataSource ds = DataSource.getByAlias("ensembl_gene_id");
assertSame(ds, BioDataSource.ENSEMBL);
}

@org.junit.Test
public void testFromUrn()
{
Xref ref = Xref.fromUrn("urn:miriam:entrez.gene:3643");
assertEquals (BioDataSource.ENTREZ_GENE, ref.getDataSource());
assertEquals ("3643", ref.getId());

ref = Xref.fromUrn("urn:miriam:blahblahblah:abc");
assertNull (ref);

ref = Xref.fromUrn("blahblahblha");
assertNull (ref);

ref = Xref.fromUrn("urn:miriam:obo.go:GO%3A00001234");
assertEquals (BioDataSource.GENE_ONTOLOGY, ref.getDataSource());
assertEquals ("GO:00001234", ref.getId());
}

}
11 changes: 11 additions & 0 deletions org.bridgedb/src/org/bridgedb/DataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public final class DataSource
private static Map<String, DataSource> byFullName = new HashMap<String, DataSource>();
private static Set<DataSource> registry = new HashSet<DataSource>();
private static Map<String, DataSource> byAlias = new HashMap<String, DataSource>();
private static Map<String, DataSource> byMiriamBase = new HashMap<String, DataSource>();

private String sysCode = null;
private String fullName = null;
Expand Down Expand Up @@ -310,6 +311,11 @@ else if (bySysCode.containsKey(sysCode))
registry.add (current);
}

if (current.urnBase != null)
{
byMiriamBase.put (current.urnBase, current);
}

current.sysCode = sysCode;
current.fullName = fullName;

Expand Down Expand Up @@ -465,4 +471,9 @@ public Object getOrganism()
return organism;
}

public static DataSource getByUrnBase(String base)
{
return byMiriamBase.get(base);
}

}
25 changes: 25 additions & 0 deletions org.bridgedb/src/org/bridgedb/Xref.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
//
package org.bridgedb;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
* Stores an id + {@link DataSource} combination, which represents
* an unique gene product.
Expand Down Expand Up @@ -108,5 +111,27 @@ public String getURN()
{
return ds.getURN (id);
}

public static Xref fromUrn(String urn)
{
int pos = urn.lastIndexOf(":");
if (pos < 0) return null;

String base = urn.substring(0, pos);
String id;
try
{
id = URLDecoder.decode(urn.substring(pos + 1), "UTF-8");
}
catch (UnsupportedEncodingException e)
{
return null;
}

DataSource ds = DataSource.getByUrnBase(base);
if (ds == null) return null;

return new Xref (id, ds);
}

}

0 comments on commit 414fd74

Please sign in to comment.