Normalizer { public String normalize(String biopaxOwlData) { if(biopaxOwlData == null || biopaxOwlData.length() == 0) throw new IllegalArgumentException("no data. " + description); biopaxOwlData = biopaxOwlData.replaceAll("taxonXref","xref"); Model model = null; try { model = biopaxReader.convertFromOWL( new ByteArrayInputStream(biopaxOwlData.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("Failed! " + description, e); } if(model == null) { throw new IllegalArgumentException("Failed to create Model! " + description); } if (model.getLevel() != BioPAXLevel.L3) { log.info("Converting model to BioPAX Level3..."); model = (new LevelUpgrader()).filter(model); } normalize(model); return convertToOWL(model); } Normalizer(); String normalize(String biopaxOwlData); static String uri(final String xmlBase, 
		String dbName, String idPart, Class<? extends BioPAXElement> type); String getDescription(); void setDescription(String description); void normalize(Model model); static void autoName(Provenance pro); static String convertToLevel3(final String biopaxData); boolean isFixDisplayName(); void setFixDisplayName(boolean fixDisplayName); String getXmlBase(); void setXmlBase(String xmlBase); static final String PROPERTY_NORMALIZER_URI_STRATEGY; static final String VALUE_NORMALIZER_URI_STRATEGY_SIMPLE; static final String VALUE_NORMALIZER_URI_STRATEGY_MD5; }
@Test public final void testNormalize() throws UnsupportedEncodingException { Model model = BioPAXLevel.L3.getDefaultFactory().createModel(); Xref ref = model.addNew(UnificationXref.class, "Xref1"); ref.setDb("uniprotkb"); ref.setId("P68250"); ProteinReference pr = model.addNew(ProteinReference.class, "ProteinReference1"); pr.setDisplayName("ProteinReference1"); pr.addXref(ref); ref = model.addNew(RelationshipXref.class, "Xref2"); ref.setDb("refseq"); ref.setId("NP_001734"); ref.setIdVersion("1"); pr.addXref(ref); ref = model.addNew(UnificationXref.class, "Xref3"); ref.setDb("uniprotkb"); ref.setId("Q0VCL1"); Xref uniprotX = ref; pr = model.addNew(ProteinReference.class, "ProteinReference2"); pr.setDisplayName("ProteinReference2"); pr.addXref(uniprotX); ref = model.addNew(RelationshipXref.class, "Xref4"); ref.setDb("refseq"); ref.setId("NP_001734"); pr.addXref(ref); pr = model.addNew(ProteinReference.class, "ProteinReference3"); pr.setDisplayName("ProteinReference3"); pr.addXref(uniprotX); ref = model.addNew(RelationshipXref.class, "Xref5"); ref.setDb("refseq"); ref.setId("NP_001734"); pr.addXref(ref); ref = model.addNew(PublicationXref.class, "Xref6"); ref.setDb("pubmed"); ref.setId("2549346"); pr.addXref(ref); ref = model.addNew(RelationshipXref.class,"Xref7"); ref.setDb("pubmed"); ref.setId("2549346"); pr.addXref(ref); ref = model.addNew(UnificationXref.class, "Xref8"); ref.setDb("taxonomy"); ref.setId("10090"); BioSource bioSource = model.addNew(BioSource.class, "BioSource_Mouse_Tissue"); bioSource.addXref((UnificationXref)ref); Provenance pro1 = model.addNew(Provenance.class, "pid"); pro1.addName("nci_nature"); pro1.setStandardName("foo"); Provenance pro2 = model.addNew(Provenance.class, "http: Pathway pw1 = model.addNew(Pathway.class, "pathway"); pw1.addDataSource(pro1); pw1.setStandardName("Pathway"); Pathway pw2 = model.addNew(Pathway.class, "sub_pathway"); pw2.setStandardName("Sub-Pathway"); pw2.addDataSource(pro2); pw1.addPathwayComponent(pw2); ref = model.addNew(UnificationXref.class, "Xref9"); ref.setDb("UniProt"); ref.setId("P68250-2"); pr = model.addNew(ProteinReference.class, "ProteinReference4"); pr.setDisplayName("ProteinReference1isoformA"); pr.addXref(ref); ref = model.addNew(UnificationXref.class, "Xref10"); ref.setDb("UniProtKb"); ref.setId("P68250"); ref.setIdVersion("2"); pr = model.addNew(ProteinReference.class, "ProteinReference5"); pr.setDisplayName("ProteinReference1isoformB"); pr.addXref(ref); ref = model.addNew(UnificationXref.class, "Xref11"); ref.setDb("UniProtKb"); ref.setId("P68250-1"); pr = model.addNew(ProteinReference.class, "ProteinReference6"); pr.addXref(ref); ref = model.addNew(UnificationXref.class, "Xref12"); ref.setDb("UniProt Isoform"); ref.setId("P68250"); ref.setIdVersion("1"); pr = model.addNew(ProteinReference.class, "ProteinReference7"); pr.addXref(ref); ref = model.addNew(UnificationXref.class, "Xref13"); ref.setDb("UniProt Isoform"); ref.setId("P68250-1"); pr = model.addNew(ProteinReference.class, "ProteinReference8"); pr.addXref(ref); UnificationXref ux = model.addNew(UnificationXref.class, "UniprotUX1"); ux.setDb("uniprot"); ux.setId("W0C7J9"); ux = model.addNew(UnificationXref.class, "UniprotUX2"); ux.setDb("uniprot"); ux.setId("W0C7J9.1"); ux = model.addNew(UnificationXref.class, "UniprotUX3"); ux.setDb("uniprot"); ux.setId("W0C7J9"); ux.setIdVersion("1"); ux = model.addNew(UnificationXref.class, "UniprotUX4"); ux.setDb("uniprot"); ux.setId("W0C7J9-1"); ux = model.addNew(UnificationXref.class, "UniprotUX5"); ux.setDb("uniprot"); ux.setId("P68250-3"); Normalizer normalizer = new Normalizer(); normalizer.normalize(model); assertTrue(model.containsID("UnificationXref_uniprot_knowledgebase_W0C7J9")); assertFalse(model.containsID("UnificationXref_uniprot_isoform_W0C7J9")); assertTrue(model.containsID("UnificationXref_uniprot_knowledgebase_W0C7J9_1")); assertTrue(model.containsID("UnificationXref_uniprot_isoform_W0C7J9-1")); assertTrue(model.containsID("UnificationXref_uniprot_isoform_P68250-3")); assertTrue(model.containsID("UnificationXref_uniprot_knowledgebase_W0C7J9")); String normUri = Normalizer.uri(model.getXmlBase(), "uniprot", "P68250", UnificationXref.class); BioPAXElement bpe = model.getByID(normUri); assertTrue(bpe instanceof UnificationXref); bpe = model.getByID("http: assertTrue(bpe instanceof ProteinReference); assertTrue(model.containsID("Xref7")); assertFalse(model.containsID("BioSource_Mouse_Tissue")); bpe = model.getByID(Normalizer.uri(model.getXmlBase(), "taxonomy", "10090", BioSource.class)); assertTrue(bpe instanceof BioSource); normUri = Normalizer.uri(model.getXmlBase(), "taxonomy", "10090", UnificationXref.class); bpe = model.getByID(normUri); assertTrue(bpe instanceof UnificationXref); assertEquals(4, model.getObjects(ProteinReference.class).size()); assertEquals(2, model.getObjects(Provenance.class).size()); pw2 = (Pathway) model.getByID("sub_pathway"); assertEquals(1, pw2.getDataSource().size()); pw1 = (Pathway) model.getByID("pathway"); assertEquals(1, pw1.getDataSource().size()); normUri = Normalizer.uri(model.getXmlBase(), "uniprot isoform", "P68250-2", UnificationXref.class); bpe = model.getByID(normUri); assertNotNull(bpe); assertEquals(1, ((Xref)bpe).getXrefOf().size()); }
@Test public final void testNormalize2() { Model model = BioPAXLevel.L3.getDefaultFactory().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); Normalizer normalizer = new Normalizer(); normalizer.normalize(model); ProteinReference e = (ProteinReference) model.getByID("http: assertNotNull(e); assertEquals(4, e.getXref().size()); }