LevelUpgrader extends AbstractTraverser implements ModelFilter { public Model filter(Model model) { if(model == null || model.getLevel() != BioPAXLevel.L2) return model; preparePep2PEIDMap(model); final Model newModel = factory.createModel(); newModel.getNameSpacePrefixMap().putAll(model.getNameSpacePrefixMap()); newModel.setXmlBase(model.getXmlBase()); normalize(model); for(BioPAXElement bpe : model.getObjects()) { Level3Element l3element = mapClass(bpe); if(l3element != null) { newModel.add(l3element); } else { log.debug("Skipping " + bpe + " " + bpe.getModelInterface().getSimpleName()); } } for(BioPAXElement e : model.getObjects()) { if(e instanceof physicalEntityParticipant || e instanceof openControlledVocabulary) { continue; } traverse((Level2Element) e, newModel); } log.info("Done: new L3 model contains " + newModel.getObjects().size() + " BioPAX individuals."); normalize(newModel); return newModel; } LevelUpgrader();  LevelUpgrader(BioPAXFactory factory); Model filter(Model model); static String getLocalId(BioPAXElement bpe);  }
@Test public final void testFilter() throws IOException { SimpleIOHandler io = new SimpleIOHandler(); Model model = io.convertFromOWL( getClass().getClassLoader() .getResourceAsStream("L2/biopax-example-short-pathway.owl")); physicalEntityParticipant pep31 = (physicalEntityParticipant) model.getByID(model.getXmlBase() + "physicalEntityParticipant31"); assertTrue(pep31 instanceof physicalEntityParticipant); assertTrue(pep31.getPHYSICAL_ENTITY() instanceof protein); assertNotNull(pep31.getCELLULAR_LOCATION()); model = (new LevelUpgrader()).filter(model); if (model != null) { io.convertToOWL(model, new FileOutputStream( getClass().getClassLoader().getResource("").getFile() + File.separator + "converted.owl")); } SmallMolecule p9 = (SmallMolecule) model.getByID(model.getXmlBase() + "physicalEntityParticipant9"); Protein p31 = (Protein) model.getByID(model.getXmlBase() + "physicalEntityParticipant31"); assertTrue(p9 instanceof SmallMolecule); assertTrue(p31 instanceof Protein); assertNotNull(p9.getCellularLocation()); assertNotNull(p31.getCellularLocation()); assertEquals(p9.getCellularLocation(), p31.getCellularLocation()); }
@Test public final void testFilterBigger() throws IOException { SimpleIOHandler io = new SimpleIOHandler(); Model model = io.convertFromOWL( getClass().getClassLoader() .getResourceAsStream("L2/biopax-example-ecocyc-glycolysis.owl")); model = (new LevelUpgrader()).filter(model); if (model != null) { io.convertToOWL(model, new FileOutputStream( getClass().getClassLoader().getResource("").getFile() + File.separator + "converted-big.owl")); } }