public static Collection<OBOObject> findParents( OBOObject oboObject, boolean recursive ) { final Collection<OBOObject> parents = Lists.newArrayList(); final Set<String> processedIdSet = Sets.newHashSet(); findParents( parents, oboObject, recursive, processedIdSet ); if ( log.isDebugEnabled() ) { log.debug( "Found " + parents.size() + " parents for term " + oboObject.getID() ); } return parents; }
public static Collection<OBOObject> findChildren( OBOObject oboObject, boolean recursive ) { List<OBOObject> children = Lists.newArrayList(); final Set<String> processedIdSet = Sets.newHashSet(); findChildren( children, oboObject, recursive, processedIdSet ); if ( log.isDebugEnabled() ) { log.debug( "Found " + children.size() + " children for term " + oboObject.getID() ); } return children; }
/** * will return a collection of TermBean accesssion strings that correspond to the root term * * @throws IllegalStateException if the parser has not been initialized */ protected Collection<String> getRootTerms() { HashSet<String> retval = new HashSet<String>(); if (parser != null) { Set<OBOObject> roots = parser.getRootTerms(useGreedy); if (roots != null) { for (OBOObject root : roots) { retval.add(safeTrim(root.getID())); } } } else { throw new IllegalStateException("Parser has not been initialized. Did you run configure()?"); } return retval; }
/** * Sometimes Cvterms with more than one parent will * have children but as it would be difficult to assign * to the right root parent class, we also create * children for each of the parent root class * * @param oboObj * @return String[] with MIs of all childresn */ private String[] getChildren4MisWithMoreParent( OBOObject oboObj ) { Collection<Link> childLinks = oboObj.getChildren(); String[] mis = new String[childLinks.size()]; int i = -1; for ( Link childLink1 : childLinks ) { Pattern p = Pattern.compile( "(MI:\\d+)-OBO_REL:is_a->(MI:\\d+)" ); Matcher m = p.matcher( childLink1.getID() ); if ( m.matches() ) { if ( m.group( 2 ).equalsIgnoreCase( oboObj.getID() ) ) { OBOObject childObj = ( OBOObject ) oboSession.getObject( m.group( 1 ) ); mis[++i] = childObj.getID(); } } } return mis; }
/** * will return a collection of TermBean accesssion strings that correspond to the root term * * @throws IllegalStateException if the parser has not been initialized */ protected Collection<String> getRootTerms() { HashSet<String> retval = new HashSet<String>(); if (parser != null) { Set<OBOObject> roots = parser.getRootTerms(useGreedy); if (roots != null) { for (OBOObject root : roots) { retval.add(safeTrim(root.getID())); } } } else { throw new IllegalStateException("Parser has not been initialized. Did you run configure()?"); } return retval; }
/** * will return a collection of TermBean accesssion strings that correspond to the root term * * @throws IllegalStateException if the parser has not been initialized */ protected Collection<String> getRootTerms() { HashSet<String> retval = new HashSet<String>(); if (parser != null) { Set<OBOObject> roots = parser.getRootTerms(useGreedy); if (roots != null) { for (OBOObject root : roots) { retval.add(safeTrim(root.getID())); } } } else { throw new IllegalStateException("Parser has not been initialized. Did you run configure()?"); } return retval; }
private static void findChildren( Collection<OBOObject> children, OBOObject oboObject, boolean recursive, Set<String> processedIdSet ) { final String id = oboObject.getID(); if( processedIdSet.contains( id ) ) { return; // cuts infinite loop as the ontology can have cycles. } else { processedIdSet.add( id ); } for ( Link childLink : oboObject.getChildren() ) { OBOObject child = (OBOObject) childLink.getChild(); children.add( child ); if( recursive && !child.getChildren().isEmpty() ) { if ( log.isTraceEnabled() ) { log.trace( "Calling recursively findChildren( "+ child.getID() +" - "+ child.getName() +" ) ..." ); } findChildren( children, child, recursive, processedIdSet ); } } }
private Collection<IdentifiedObject> getChildren( OBOSession source, String miTerm ) { OBOObject parentTerm = ( OBOObject ) source.getObject( miTerm ); Collection<Link> childLinks = parentTerm.getChildren(); Collection<IdentifiedObject> children = new ArrayList<IdentifiedObject>(); for ( Link childLink : childLinks ) { OBOObject childTerm = ( OBOObject ) childLink.getChild(); children.add( childTerm ); children.addAll( getChildren( source, childTerm.getID() ) ); } return children; }
private static void findParents( Collection<OBOObject> parents, OBOObject oboObject, boolean recursive, Set<String> processedIdSet ) { final String id = oboObject.getID(); if( processedIdSet.contains( id ) ) { return; // cuts infinite loop as the ontology can have cycles. } else { processedIdSet.add( id ); } for ( Link parentLink : oboObject.getParents() ) { OBOObject parent = (OBOObject) parentLink.getParent(); parents.add( parent ); if( recursive && !parent.getParents().isEmpty() ) { if ( log.isTraceEnabled() ) { log.trace( "Calling recursively findParent( "+ parent.getID() +" - "+ parent.getName() +" ) ..." ); } findParents( parents, parent, recursive, processedIdSet ); } } }
/** * Once all the term objects have been created, this method will create the relationships and paths * to link all the children terms to a given parent term and update the OLS TermBean object with * the proper information from the global term storage. * * @param obj - the OBOEdit term object that will be used to extract information from */ private void processLookupTermRelationships(OBOObject obj) { if (obj.getID().startsWith("obo:")) { /* obo:datatype obo:property obo:class */ logger.debug("bogus term: " + obj.getID()); return; } TermBean trm = (TermBean) ontologyTerms.get(safeTrim(obj.getID())); trm.setRelationships(processLookupRelationships(obj, trm)); trm.setPaths(processLookupPaths(obj, trm)); //update term object ontologyTerms.put(trm.getIdentifier(), trm); }
/** * Once all the term objects have been created, this method will create the relationships and paths * to link all the children terms to a given parent term and update the OLS TermBean object with * the proper information from the global term storage. * * @param obj - the OBOEdit term object that will be used to extract information from */ private void processTermRelationships(OBOObject obj) { if (obj.getID().startsWith("obo:")) { /* obo:datatype obo:property obo:class */ logger.debug("bogus term: " + obj.getID()); return; } TermBean trm = (TermBean) ontologyTerms.get(safeTrim(obj.getID())); trm.setRelationships(processRelationships(obj, trm)); trm.setPaths(processPaths(obj, trm)); //update term object ontologyTerms.put(trm.getIdentifier(), trm); }
/** * Once all the term objects have been created, this method will create the relationships and paths * to link all the children terms to a given parent term and update the OLS TermBean object with * the proper information from the global term storage. * * @param obj - the OBOEdit term object that will be used to extract information from */ private void processTermRelationships(OBOObject obj) { if (obj.getID().startsWith("obo:")) { /* obo:datatype obo:property obo:class */ logger.debug("bogus term: " + obj.getID()); return; } TermBean trm = (TermBean) ontologyTerms.get(safeTrim(obj.getID())); trm.setRelationships(processRelationships(obj, trm)); trm.setPaths(processPaths(obj, trm)); //update term object ontologyTerms.put(trm.getIdentifier(), trm); }
/** * Once all the term objects have been created, this method will create the relationships and paths * to link all the children terms to a given parent term and update the OLS TermBean object with * the proper information from the global term storage. * * @param obj - the OBOEdit term object that will be used to extract information from */ private void processTermRelationships(OBOObject obj) { if (obj.getID().startsWith("obo:")) { /* obo:datatype obo:property obo:class */ logger.debug("bogus term: " + obj.getID()); return; } TermBean trm = (TermBean) ontologyTerms.get(safeTrim(obj.getID())); trm.setRelationships(processRelationships(obj, trm)); trm.setPaths(processPaths(obj, trm)); //update term object ontologyTerms.put(trm.getIdentifier(), trm); }
hashSet.add(cvClass.getSimpleName()); map4misWithMoreParent.put(oboObj.getID(), hashSet);
public Collection<IdentifiedObject> getOrphanOBOObjects() { Collection<IdentifiedObject> orphanOboObjects = new ArrayList<IdentifiedObject>(); Collection<IdentifiedObject> allOBOObjects = oboSession.getObjects(); for ( IdentifiedObject identifiedObject : allOBOObjects ) { if ( identifiedObject.getID().startsWith( "MI:" ) ) { if ( identifiedObject instanceof OBOObject ) { OBOObject obj = ( OBOObject ) identifiedObject; Class<? extends CvObject> cvClass = findCvClassforMI( obj.getID() ); //if CvClass is null then no parent if ( cvClass == null ) { if ( !identifiedObject.getID().startsWith( MI_ROOT_IDENTIFIER ) ) { orphanOboObjects.add( identifiedObject ); } } } } } return orphanOboObjects; }
OBOObject rootObject = ( OBOObject ) rootOboObject; if ( log.isTraceEnabled() ) log.trace( "Adding Parent Object " + rootObject.getID() );
log.debug( " targetTerm ID: " + targetTerm.getID() + " Name: " + targetTerm.getName() + " Children: " + targetTerm.getChildren().size() ); log.debug( " sourceTerm ID: " + sourceTerm.getID() + " Name: " + sourceTerm.getName() + " Children: " + sourceTerm.getChildren().size() ); log.debug( " sourceChildren size: " + children.size() ); log.debug( " targetTermAfter " + targetTermAfter.getID() + " " + targetTermAfter.getName() + " " + targetTermAfter.getChildren().size() );
if (obj.getID().startsWith("obo:")) { logger.debug("bogus term: " + obj.getID()); return; trm.setTermPk(safeTrim(obj.getID()) + SHORT_NAME + "0"); if (trm.getTermPk().length() > 255) { throw new IllegalStateException("term PK longer than allowed database column length: " + trm.getTermPk()); trm.setIdentifier(safeTrim(obj.getID())); if (trm.getIdentifier() != null && trm.getIdentifier().length() > 255) { logger.warn("term identifier longer than allowed database column length - truncating" + trm.getIdentifier()); if (rootTerms.contains(safeTrim(obj.getID()))) { trm.setRootTerm(true); logger.info(obj.getID() + " is a root term");
if (obj.getID().startsWith("obo:")) { logger.debug("bogus term: " + obj.getID()); return; trm.setTermPk(safeTrim(obj.getID()) + SHORT_NAME + "0"); if (trm.getTermPk().length() > 255) { throw new IllegalStateException("term PK longer than allowed database column length: " + trm.getTermPk()); trm.setIdentifier(safeTrim(obj.getID())); if (trm.getIdentifier() != null && trm.getIdentifier().length() > 255) { logger.warn("term identifier longer than allowed database column length - truncating" + trm.getIdentifier()); if (rootTerms.contains(safeTrim(obj.getID()))) { trm.setRootTerm(true); logger.info(obj.getID() + " is a root term");