@Test public final void testRemoveObjectsIfDangling() { Model model = (new SimpleIOHandler()).convertFromOWL( getClass().getClassLoader().getResourceAsStream("L3" + File.separator + "hcyc.owl")); assertEquals(6, model.getObjects().size()); ModelUtils.removeObjectsIfDangling(model, UtilityClass.class); assertEquals(6, model.getObjects().size()); SmallMolecule sm1 = (SmallMolecule) model.getByID("SM1"); SmallMoleculeReference smr1 = (SmallMoleculeReference) model.getByID("SMR1"); SmallMoleculeReference a = (SmallMoleculeReference) model.getByID("A"); assertNotNull(smr1); assertTrue(smr1.getMemberEntityReference().contains(a)); sm1.setEntityReference(null); model.remove(smr1); assertTrue(smr1.getEntityReferenceOf().isEmpty()); ModelUtils.removeObjectsIfDangling(model, UtilityClass.class); assertNull(model.getByID("SMR1")); assertNull(model.getByID("A")); SmallMoleculeReference b = (SmallMoleculeReference) model.getByID("B"); assertNotNull(b); assertEquals(4, model.getObjects().size()); assertEquals(3, b.getMemberEntityReferenceOf().size()); assertTrue(a.getMemberEntityReference().contains(b)); assertTrue(smr1.getMemberEntityReference().contains(b)); }
public static <T extends BioPAXElement> Set<BioPAXElement> removeObjectsIfDangling(Model model, Class<T> clazz) { final Set<BioPAXElement> removed = new HashSet<BioPAXElement>(); if(Entity.class.equals(clazz)) { LOG.warn("Ignored removeObjectsIfDangling call for: " + "Entity.class (it would delete all)"); return removed; } if(UtilityClass.class.equals(clazz) && getRootElements(model, Entity.class).isEmpty()) { LOG.warn("Ignored removeObjectsIfDangling call: " + "no root entities model; UtilityClass.class"); return removed; } Set<T> dangling = getRootElements(model, clazz); if (!dangling.isEmpty()) { LOG.info(dangling.size() + " " + clazz.getSimpleName() + " dangling objects will be deleted..."); for (BioPAXElement thing : dangling) { model.remove(thing); removed.add(thing); LOG.debug("removed (dangling) " + thing.getUri() + " (" + thing.getModelInterface().getSimpleName() + ") " + thing); } removed.addAll(removeObjectsIfDangling(model, clazz)); } return removed; }
ModelUtils { public static <T extends BioPAXElement> Set<BioPAXElement> removeObjectsIfDangling(Model model, Class<T> clazz) { final Set<BioPAXElement> removed = new HashSet<BioPAXElement>(); if(Entity.class.equals(clazz)) { LOG.warn("Ignored removeObjectsIfDangling call for: " + "Entity.class (it would delete all)"); return removed; } if(UtilityClass.class.equals(clazz) && getRootElements(model, Entity.class).isEmpty()) { LOG.warn("Ignored removeObjectsIfDangling call: " + "no root entities model; UtilityClass.class"); return removed; } Set<T> dangling = getRootElements(model, clazz); if (!dangling.isEmpty()) { LOG.info(dangling.size() + " " + clazz.getSimpleName() + " dangling objects will be deleted..."); for (BioPAXElement thing : dangling) { model.remove(thing); removed.add(thing); LOG.debug("removed (dangling) " + thing.getUri() + " (" + thing.getModelInterface().getSimpleName() + ") " + thing); } removed.addAll(removeObjectsIfDangling(model, clazz)); } return removed; } }
ModelUtils { public static <T extends BioPAXElement> Set<BioPAXElement> removeObjectsIfDangling(Model model, Class<T> clazz) { final Set<BioPAXElement> removed = new HashSet<BioPAXElement>(); if(Entity.class.equals(clazz)) { LOG.warn("Ignored removeObjectsIfDangling call for: " + "Entity.class (it would delete all)"); return removed; } if(UtilityClass.class.equals(clazz) && getRootElements(model, Entity.class).isEmpty()) { LOG.warn("Ignored removeObjectsIfDangling call: " + "no root entities model; UtilityClass.class"); return removed; } Set<T> dangling = getRootElements(model, clazz); if (!dangling.isEmpty()) { LOG.info(dangling.size() + " " + clazz.getSimpleName() + " dangling objects will be deleted..."); for (BioPAXElement thing : dangling) { model.remove(thing); removed.add(thing); LOG.debug("removed (dangling) " + thing.getUri() + " (" + thing.getModelInterface().getSimpleName() + ") " + thing); } removed.addAll(removeObjectsIfDangling(model, clazz)); } return removed; } ModelUtils(); }
ModelUtils { public static <T extends BioPAXElement> Set<BioPAXElement> removeObjectsIfDangling(Model model, Class<T> clazz) { final Set<BioPAXElement> removed = new HashSet<BioPAXElement>(); if(Entity.class.equals(clazz)) { LOG.warn("Ignored removeObjectsIfDangling call for: " + "Entity.class (it would delete all)"); return removed; } if(UtilityClass.class.equals(clazz) && getRootElements(model, Entity.class).isEmpty()) { LOG.warn("Ignored removeObjectsIfDangling call: " + "no root entities model; UtilityClass.class"); return removed; } Set<T> dangling = getRootElements(model, clazz); if (!dangling.isEmpty()) { LOG.info(dangling.size() + " " + clazz.getSimpleName() + " dangling objects will be deleted..."); for (BioPAXElement thing : dangling) { model.remove(thing); removed.add(thing); LOG.debug("removed (dangling) " + thing.getUri() + " (" + thing.getModelInterface().getSimpleName() + ") " + thing); } removed.addAll(removeObjectsIfDangling(model, clazz)); } return removed; } ModelUtils(); static void replace(Model model, final Map<? extends BioPAXElement, ? extends BioPAXElement> subs); static Set<T> getRootElements(final Model model, final Class<T> filterClass); static Set<BioPAXElement> removeObjectsIfDangling(Model model, Class<T> clazz); static Model writeRead(Model model); static Model getDirectChildren(BioPAXElement bpe); static Model getAllChildren(BioPAXElement bpe, 
		@SuppressWarnings("rawtypes") Filter<PropertyEditor>... filters); static Set<BioPAXElement> getDirectChildrenAsSet(BioPAXElement bpe); static Map<Class<? extends BioPAXElement>, Integer> generateClassMetrics(Model model); static T getObject(Model model, String uri, Class<T> clazz); static String md5hex(String id); static void fixDanglingObjectProperties(BioPAXElement bpe, Model model); static void fixDanglingInverseProperties(BioPAXElement bpe, Model model); static Set<EntityFeature> getFeatureIntersection(PhysicalEntity first, FeatureType firstClass,
			PhysicalEntity second, FeatureType secondClass); static Set<EntityFeature> getFeatureSetByType(PhysicalEntity pe, FeatureType type); static boolean checkERFeatureSet(EntityReference er, boolean fix); static Set<EntityFeature> findFeaturesAddedToSecond(PhysicalEntity first, PhysicalEntity second,
			boolean fix); static void fixControlled(Model model, Control control); static void normalizeGeneric(Model model, PhysicalEntity generic); static void normalizeGenerics(Model model); static void addMissingEntityReference(Model model, SimplePhysicalEntity pe); static void replaceEquivalentFeatures(Model model); static Set<String> getKeywords(BioPAXElement biopaxElement, int depth,
										  Filter<DataPropertyEditor>... dataPropertyFilters); static Set<BioSource> getOrganisms(BioPAXElement biopaxElement); static Set<Provenance> getDatasources(BioPAXElement biopaxElement); static Set<Pathway> getParentPathways(BioPAXElement biopaxElement); static void mergeEquivalentInteractions(Model model); static void mergeEquivalentPhysicalEntities(Model model); static String encodeBase62(String str); static String shortenUri(String xmlbase, String uri); static void updateUri(Model model, BioPAXElement el, String newUri); static void breakPathwayComponentCycle(final Model model); static boolean isGeneric(BioPAXElement e); }
ModelUtils { public static <T extends BioPAXElement> Set<BioPAXElement> removeObjectsIfDangling(Model model, Class<T> clazz) { final Set<BioPAXElement> removed = new HashSet<BioPAXElement>(); if(Entity.class.equals(clazz)) { LOG.warn("Ignored removeObjectsIfDangling call for: " + "Entity.class (it would delete all)"); return removed; } if(UtilityClass.class.equals(clazz) && getRootElements(model, Entity.class).isEmpty()) { LOG.warn("Ignored removeObjectsIfDangling call: " + "no root entities model; UtilityClass.class"); return removed; } Set<T> dangling = getRootElements(model, clazz); if (!dangling.isEmpty()) { LOG.info(dangling.size() + " " + clazz.getSimpleName() + " dangling objects will be deleted..."); for (BioPAXElement thing : dangling) { model.remove(thing); removed.add(thing); LOG.debug("removed (dangling) " + thing.getUri() + " (" + thing.getModelInterface().getSimpleName() + ") " + thing); } removed.addAll(removeObjectsIfDangling(model, clazz)); } return removed; } ModelUtils(); static void replace(Model model, final Map<? extends BioPAXElement, ? extends BioPAXElement> subs); static Set<T> getRootElements(final Model model, final Class<T> filterClass); static Set<BioPAXElement> removeObjectsIfDangling(Model model, Class<T> clazz); static Model writeRead(Model model); static Model getDirectChildren(BioPAXElement bpe); static Model getAllChildren(BioPAXElement bpe, 
		@SuppressWarnings("rawtypes") Filter<PropertyEditor>... filters); static Set<BioPAXElement> getDirectChildrenAsSet(BioPAXElement bpe); static Map<Class<? extends BioPAXElement>, Integer> generateClassMetrics(Model model); static T getObject(Model model, String uri, Class<T> clazz); static String md5hex(String id); static void fixDanglingObjectProperties(BioPAXElement bpe, Model model); static void fixDanglingInverseProperties(BioPAXElement bpe, Model model); static Set<EntityFeature> getFeatureIntersection(PhysicalEntity first, FeatureType firstClass,
			PhysicalEntity second, FeatureType secondClass); static Set<EntityFeature> getFeatureSetByType(PhysicalEntity pe, FeatureType type); static boolean checkERFeatureSet(EntityReference er, boolean fix); static Set<EntityFeature> findFeaturesAddedToSecond(PhysicalEntity first, PhysicalEntity second,
			boolean fix); static void fixControlled(Model model, Control control); static void normalizeGeneric(Model model, PhysicalEntity generic); static void normalizeGenerics(Model model); static void addMissingEntityReference(Model model, SimplePhysicalEntity pe); static void replaceEquivalentFeatures(Model model); static Set<String> getKeywords(BioPAXElement biopaxElement, int depth,
										  Filter<DataPropertyEditor>... dataPropertyFilters); static Set<BioSource> getOrganisms(BioPAXElement biopaxElement); static Set<Provenance> getDatasources(BioPAXElement biopaxElement); static Set<Pathway> getParentPathways(BioPAXElement biopaxElement); static void mergeEquivalentInteractions(Model model); static void mergeEquivalentPhysicalEntities(Model model); static String encodeBase62(String str); static String shortenUri(String xmlbase, String uri); static void updateUri(Model model, BioPAXElement el, String newUri); static void breakPathwayComponentCycle(final Model model); static boolean isGeneric(BioPAXElement e);  }