SimpleMerger { public void merge(Model target, Model... sources) { for (Model source : sources) if (source != null) merge(target, source.getObjects()); } SimpleMerger(EditorMap map);  SimpleMerger(EditorMap map, Filter<BioPAXElement> mergePropOf); void merge(Model target, Model... sources); void merge(Model target, Collection<? extends BioPAXElement> elements); void merge(Model target, BioPAXElement source);  }
@Test public final void testMergeModel() { BioPAXFactory factory = BioPAXLevel.L3.getDefaultFactory(); Model model = factory.createModel(); Xref ref = model.addNew(UnificationXref.class, "Xref1"); ref.setDb("uniprotkb"); ref.setId("Q0VCL1"); Xref uniprotX = ref; ProteinReference pr = model.addNew(ProteinReference.class, "ProteinReference"); pr.setDisplayName("ProteinReference"); pr.addXref(uniprotX); ref = model.addNew(RelationshipXref.class, "Xref2"); ref.setDb("refseq"); ref.setId("NP_001734"); pr.addXref(ref); ref = model.addNew(PublicationXref.class, "Xref3"); ref.setDb("pubmed"); ref.setId("2549346"); pr.addXref(ref); ref = model.addNew(RelationshipXref.class,"Xref4"); ref.setDb("pubmed"); ref.setId("2549346"); pr.addXref(ref); BioSource bs = factory.create(BioSource.class, "Mouse"); ref = factory.create(UnificationXref.class, "Xref5"); ref.setDb("taxonomy"); ref.setId("10090"); bs.addXref(ref); pr.setOrganism(bs); assertEquals(5, model.getObjects().size()); SimpleMerger merger = new SimpleMerger(SimpleEditorMap.L3); merger.merge(model, model); bs = (BioSource) model.getByID("Mouse"); assertEquals(1, bs.getXref().size()); pr = (ProteinReference) model.getByID("ProteinReference"); assertEquals(4, pr.getXref().size()); assertEquals(7, model.getObjects().size()); }
@Test public final void testMergeObject() { SimpleMerger merger = new SimpleMerger(SimpleEditorMap.L3); BioPAXFactory factory = BioPAXLevel.L3.getDefaultFactory(); Model model = factory.createModel(); Xref ref = factory.create(UnificationXref.class, "9606"); ref.setDb("Taxonomy"); ref.setId("9606"); BioSource bs = factory.create(BioSource.class, "Human"); bs.addXref(ref); merger.merge(model, ref); assertEquals(1, model.getObjects().size()); merger.merge(model, bs); assertEquals(2, model.getObjects().size()); model = factory.createModel(); merger.merge(model, bs); assertEquals(2, model.getObjects().size()); }
@Test public final void testMergeToInconsistentModel() { BioPAXFactory factory = BioPAXLevel.L3.getDefaultFactory(); Model model = factory.createModel(); Xref mref =factory.create(UnificationXref.class, "10090"); mref.setDb("Taxonomy"); mref.setId("10090"); BioSource mouse = model.addNew(BioSource.class, "mouse"); mouse.addXref(mref); assertEquals(1, model.getObjects().size()); Xref href = factory.create(UnificationXref.class, "9606"); href.setDb("Taxonomy"); href.setId("9606"); BioSource human = factory.create(BioSource.class, "human"); human.addXref(href); SimpleMerger merger = new SimpleMerger(SimpleEditorMap.L3); merger.merge(model, human); assertEquals(3, model.getObjects().size()); assertNull(model.getByID("10090")); model = factory.createModel(); mref = factory.create(UnificationXref.class, "ref"); mref.setDb("Taxonomy"); mref.setId("10090"); mouse = model.addNew(BioSource.class, "mouse"); mouse.addXref(mref); href = factory.create(UnificationXref.class, "ref"); href.setDb("Taxonomy"); href.setId("9606"); human = factory.create(BioSource.class, "human"); human.addXref(href); merger.merge(model, human); assertEquals(3, model.getObjects().size()); Xref x = (UnificationXref)model.getByID("ref"); assertNotNull(x); assertEquals("9606", x.getId()); BioSource bs = (BioSource) model.getByID("mouse"); assertNotNull(bs); assertEquals("10090", bs.getXref().iterator().next().getId()); assertEquals("9606", human.getXref().iterator().next().getId()); model = factory.createModel(); mref = model.addNew(UnificationXref.class, "ref"); mref.setDb("Taxonomy"); mref.setId("10090"); mouse = model.addNew(BioSource.class, "mouse"); mouse.addXref(mref); merger.merge(model, human); assertEquals(3, model.getObjects().size()); x = (UnificationXref)model.getByID("ref"); assertNotNull(x); assertEquals("10090", x.getId()); bs = (BioSource) model.getByID("mouse"); assertNotNull(bs); assertEquals("10090", bs.getXref().iterator().next().getId()); assertNotNull(model.getByID("human")); assertEquals("10090", human.getXref().iterator().next().getId()); }
@Test public final void testMergeWithoutFilter() { BioPAXFactory factory = BioPAXLevel.L3.getDefaultFactory(); Model model = factory.createModel(); BioSource human = model.addNew(BioSource.class, "human"); human.setStandardName("Homo sapiens"); UnificationXref uxHuman = model.addNew(UnificationXref.class, "9606"); human.addXref(uxHuman); ProteinReference pr = model.addNew(ProteinReference.class, "pr"); pr.setDisplayName("one"); pr.setOrganism(human); ProteinReference pr1 = factory.create(ProteinReference.class, "pr"); Xref ux = factory.create(UnificationXref.class, "ux"); ux.setDb("UniProt"); ux.setId("P12345"); pr1.addName("one"); pr1.addName("two"); pr1.addXref(ux); UnificationXref uxHuman1 = factory.create(UnificationXref.class, "9606"); BioSource human1 = factory.create(BioSource.class, "human"); human1.addXref(uxHuman1); human1.setDisplayName("human"); pr1.setOrganism(human1); PublicationXref px = factory.create(PublicationXref.class, "publication"); human1.addXref(px); SimpleMerger merger = new SimpleMerger(SimpleEditorMap.L3); merger.merge(model, pr1); assertEquals(5, model.getObjects().size()); ProteinReference mergedPr = (ProteinReference) model.getByID("pr"); assertTrue(mergedPr.getXref().isEmpty()); assertEquals("one", mergedPr.getDisplayName()); assertEquals(1, mergedPr.getName().size()); assertEquals("Homo sapiens", mergedPr.getOrganism().getStandardName()); assertNull(mergedPr.getOrganism().getDisplayName()); assertEquals(1, mergedPr.getOrganism().getName().size()); assertNotNull(model.getByID("publication")); assertEquals(1, mergedPr.getOrganism().getXref().size()); assertEquals(uxHuman, mergedPr.getOrganism().getXref().iterator().next()); }
@Test public final void testMergeWithFilter() { BioPAXFactory factory = BioPAXLevel.L3.getDefaultFactory(); Model model = factory.createModel(); BioSource human = model.addNew(BioSource.class, "human"); human.setStandardName("Homo sapiens"); UnificationXref uxHuman = model.addNew(UnificationXref.class, "9606"); uxHuman.setDb("taxonomy"); uxHuman.setId("9606"); human.addXref(uxHuman); ProteinReference pr = model.addNew(ProteinReference.class, "pr"); pr.setDisplayName("one"); pr.setOrganism(human); ProteinReference pr1 = factory.create(ProteinReference.class, "pr"); Xref ux = factory.create(UnificationXref.class, "ux"); ux.setDb("UniProt"); ux.setId("P12345"); pr1.addName("one"); pr1.addName("two"); pr1.addXref(ux); UnificationXref uxHuman1 = factory.create(UnificationXref.class, "9606"); uxHuman1.setDb("Taxonomy"); uxHuman1.setId("9606"); BioSource human1 = factory.create(BioSource.class, "human"); human1.addXref(uxHuman1); human1.setDisplayName("human"); pr1.setOrganism(human1); PublicationXref px = factory.create(PublicationXref.class, "publication"); px.setId("00000"); px.setDb("PubMed"); human1.addXref(px); SimpleMerger merger = new SimpleMerger(SimpleEditorMap.L3, new Filter<BioPAXElement>() { public boolean filter(BioPAXElement object) { return object instanceof EntityReference; } }); merger.merge(model, pr1); assertEquals(5, model.getObjects().size()); ProteinReference mergedPr = (ProteinReference) model.getByID("pr"); assertFalse(mergedPr.getXref().isEmpty()); assertEquals("one", mergedPr.getDisplayName()); assertEquals(2, mergedPr.getName().size()); assertEquals("Homo sapiens", mergedPr.getOrganism().getStandardName()); assertNull(mergedPr.getOrganism().getDisplayName()); assertEquals(1, mergedPr.getOrganism().getName().size()); assertEquals(1, mergedPr.getOrganism().getXref().size()); px = (PublicationXref)model.getByID("publication"); assertNotNull(px); for(XReferrable xReferrable : px.getXrefOf()) assertFalse(model.contains(xReferrable)); merger = new SimpleMerger(SimpleEditorMap.L3, new Filter<BioPAXElement>() { public boolean filter(BioPAXElement object) { return object instanceof EntityReference || object instanceof BioSource; } }); model = factory.createModel(); model.add(pr); model.add(human); model.add(uxHuman); merger.merge(model, pr1); assertEquals(5, model.getObjects().size()); mergedPr = (ProteinReference) model.getByID("pr"); assertFalse(mergedPr.getXref().isEmpty()); assertEquals("one", mergedPr.getDisplayName()); assertEquals(2, mergedPr.getName().size()); assertEquals("Homo sapiens", mergedPr.getOrganism().getStandardName()); assertNull(mergedPr.getOrganism().getDisplayName()); assertEquals(2, mergedPr.getOrganism().getName().size()); assertTrue(mergedPr.getOrganism().getName().contains("human")); assertEquals(2, mergedPr.getOrganism().getXref().size()); px = (PublicationXref)model.getByID("publication"); assertNotNull(px); assertTrue(mergedPr.getOrganism().getXref().contains(px)); assertTrue(mergedPr.getOrganism().getXref().contains(uxHuman)); assertFalse(mergedPr.getOrganism().getXref().contains(uxHuman1)); }