Skip to content

Commit

Permalink
Work on transitive mapping in Stack
Browse files Browse the repository at this point in the history
Also added unit test and data file
Not yet implemented for mapID(Set<Xref>, ...

git-svn-id: http://svn.bigcat.unimaas.nl/bridgedb/trunk@168 e3f1d335-44b1-4163-9530-9b341189ae98
  • Loading branch information
martijn committed Aug 22, 2009
1 parent 2f0a926 commit ab0a4ce
Show file tree
Hide file tree
Showing 3 changed files with 5,290 additions and 9 deletions.
58 changes: 50 additions & 8 deletions bio/test/org/bridgedb/bio/TestStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@

public class TestStack extends TestCase
{

static final String GDB_HUMAN =
private static final String GDB_HUMAN =
System.getProperty ("user.home") + File.separator +
"PathVisio-Data/gene databases/Hs_Derby_20081119.pgdb";
static final File YEAST_ID_MAPPING = new File ("../test-data/yeast_id_mapping.txt");
private static final File YEAST_ID_MAPPING = new File ("../test-data/yeast_id_mapping.txt");
private static final File NUGO_CUSTOM_MAPPINGS = new File ("/home/martijn/prg/bridgedb/test-data/Nugo-hs-custom.txt");

private Set<Xref> src = new HashSet<Xref>();
private Set<DataSource> dsset = new HashSet<DataSource>();
private static final Xref RAD51 = new Xref ("YER095W", BioDataSource.ENSEMBL_SCEREVISIAE);
private static final Xref INSR = new Xref ("Hs.705877", BioDataSource.UNIGENE);

private static final Xref NUGO = new Xref ("NuGO_eht0320285_at", BioDataSource.AFFY);
private static final Xref ENSEMBL = new Xref ("ENSG00000026652", BioDataSource.ENSEMBL);
private static final Xref ENTREZ = new Xref ("56895", BioDataSource.ENTREZ_GENE);

Set<Xref> src = new HashSet<Xref>();
Set<DataSource> dsset = new HashSet<DataSource>();
static final Xref RAD51 = new Xref ("YER095W", BioDataSource.ENSEMBL_SCEREVISIAE);
static final Xref INSR = new Xref ("Hs.705877", BioDataSource.UNIGENE);

public void setUp() throws ClassNotFoundException
{
BioDataSource.init();
Expand Down Expand Up @@ -81,5 +85,43 @@ public void testStack() throws IDMapperException, MalformedURLException
expected.add (new Xref ("856831", BioDataSource.ENTREZ_GENE));
assertEquals (expected, refmap.get(RAD51));
}

public void testTransitive() throws IDMapperException, ClassNotFoundException, MalformedURLException
{
IDMapper textMapper = BridgeDb.connect ("idmapper-text:" + NUGO_CUSTOM_MAPPINGS.toURL());
IDMapper derbyMapper = BridgeDb.connect ("idmapper-pgdb:" + GDB_HUMAN);
IDMapperStack stack = new IDMapperStack();
stack.addIDMapper(derbyMapper);
stack.addIDMapper(textMapper);

stack.setTransitive(false);

// test the link between NUGO and ENSEMBL that only occurs in text
Set<Xref> result = stack.mapID(NUGO, null);
assertTrue(result.contains(ENSEMBL));
assertFalse(result.contains(ENTREZ));

// test the link between ENTREZ and ENSEMBL that only occurs in pgdb
result = stack.mapID(ENTREZ, null);
assertFalse(result.contains(NUGO));
assertTrue(result.contains(ENSEMBL));

stack.setTransitive(true);

// test transitive
result = stack.mapID(NUGO, null);
assertTrue(result.contains(ENTREZ));
assertTrue(result.contains(ENSEMBL));

// and the other way around
result = stack.mapID(ENTREZ, null);
assertTrue(result.contains(NUGO));
assertTrue(result.contains(ENSEMBL));

// map multiple IDs
Set<Xref> set1 = new HashSet<Xref>();
set1.add (ENTREZ);
Map<Xref, Set<Xref>> result2 = stack.mapID(set1, null);
assertTrue (result2.get(ENTREZ).contains(NUGO));
}
}
21 changes: 20 additions & 1 deletion corelib/src/org/bridgedb/IDMapperStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,26 @@ public Set<Xref> mapID(Xref ref, Set<DataSource> resultDs) throws IDMapperExcept
*/
private Set<Xref> mapIDtransitive(Xref ref, Set<DataSource> resultDs) throws IDMapperException
{
throw new UnsupportedOperationException();
// first round
Set<Xref> round1 = new HashSet<Xref>();
for (IDMapper child : gdbs)
{
if (child != null && child.isConnected())
{
round1.addAll (child.mapID(ref, null));
}
}
// second round
Set<Xref> round2 = new HashSet<Xref>();
for (IDMapper child : gdbs)
{
if (child != null && child.isConnected())
{
for (Set<Xref> set : child.mapID(round1, resultDs).values())
round2.addAll (set);
}
}
return round2;
}

/**
Expand Down
Loading

0 comments on commit ab0a4ce

Please sign in to comment.