GoClassReferenceAnnotationRule extends AbstractAnnotationRule { @Override public Set<AnnotationRuleViolation> getRuleViolations(GeneAnnotation a) { HashSet<AnnotationRuleViolation> set = new HashSet<AnnotationRuleViolation>(); String id = a.getCls(); OWLClass owlClass = graph.getOWLClassByIdentifierNoAltIds(id); if (owlClass == null) { OWLObject owlObject = owlObjectsByAltId.get(id); if (owlObject == null) { set.add(new AnnotationRuleViolation(getRuleId(), "The id '"+id+"' in the annotation is a dangling reference", a)); } else { String mainId = graph.getIdentifier(owlObject); set.add(new AnnotationRuleViolation(getRuleId(), "The id '"+id+"' in the annotation is an alternate id for: "+mainId, a, ViolationType.Warning)); } } else { boolean isObsolete = graph.isObsolete(owlClass); if (isObsolete) { StringBuilder msg = new StringBuilder(); msg.append("The id '").append(id).append("' in the annotation is an obsolete class"); List<String> replacedBy = graph.getReplacedBy(owlClass); if (replacedBy != null && !replacedBy.isEmpty()) { msg.append(", suggested replacements:"); for (String replace : replacedBy) { msg.append(' ').append(replace); } } set.add(new AnnotationRuleViolation(getRuleId(), msg.toString(), a)); } } List<List<ExtensionExpression>> groupedExpressions = a.getExtensionExpressions(); if (groupedExpressions != null && !groupedExpressions.isEmpty()) { for (List<ExtensionExpression> expressions : groupedExpressions) { for (ExtensionExpression expression : expressions) { String exId = expression.getCls(); boolean doCheck = false; for(String idPrefix : c16PrefixWhiteList) { if (exId.startsWith(idPrefix)) { doCheck = true; break; } } if (doCheck) { OWLClass exCls = graph.getOWLClassByIdentifierNoAltIds(exId); if (exCls == null) { OWLObject owlObject = owlObjectsByAltId.get(exId); if (owlObject == null) { set.add(new AnnotationRuleViolation(getRuleId(), "The id '"+exId+"' in the c16 annotation extension is a dangling reference", a)); } else { String mainId = graph.getIdentifier(owlObject); set.add(new AnnotationRuleViolation(getRuleId(), "The id '"+exId+"' in the c16 annotation extension is an alternate id for: "+mainId, a, ViolationType.Warning)); } } else { boolean isObsolete = graph.isObsolete(exCls); if (isObsolete) { StringBuilder msg = new StringBuilder(); msg.append("The id '").append(exId).append("' in the c16 annotation extension is an obsolete class"); List<String> replacedBy = graph.getReplacedBy(exCls); if (replacedBy != null && !replacedBy.isEmpty()) { msg.append(", suggested replacements:"); for (String replace : replacedBy) { msg.append(' ').append(replace); } } set.add(new AnnotationRuleViolation(getRuleId(), msg.toString(), a)); } } } String exRel = expression.getRelation(); OWLObjectProperty rel = graph.getOWLObjectPropertyByIdentifier(exRel); if (rel == null) { rel = relByAltId.get(rel); if (rel == null) { set.add(new AnnotationRuleViolation(getRuleId(), "The relation '"+exRel+"' in the c16 annotation extension is a dangling reference", a)); } else { String mainId = graph.getIdentifier(rel); set.add(new AnnotationRuleViolation(getRuleId(), "The relation '"+exRel+"' in the c16 annotation extension is an alternate id for: "+mainId, a, ViolationType.Warning)); } } else { boolean isObsolete = graph.isObsolete(rel); if (isObsolete) { StringBuilder msg = new StringBuilder(); msg.append("The relation '").append(exRel).append("' in the c16 annotation extension is an obsolete relation"); List<String> replacedBy = graph.getReplacedBy(rel); if (replacedBy != null && !replacedBy.isEmpty()) { msg.append(", suggested replacements:"); for (String replace : replacedBy) { msg.append(' ').append(replace); } } set.add(new AnnotationRuleViolation(getRuleId(), msg.toString(), a)); } } } } } return set; } GoClassReferenceAnnotationRule(OWLGraphWrapper wrapper, String...idPrefixes); @Override Set<AnnotationRuleViolation> getRuleViolations(GeneAnnotation a); static final String PERMANENT_JAVA_ID; }
@Test public void test() throws Exception { GafDocument gafdoc = loadZippedGaf("gene_association.goa_human.gz"); GoClassReferenceAnnotationRule rule = new GoClassReferenceAnnotationRule(graph, "GO:","CL:"); List<GeneAnnotation> annotations = gafdoc.getGeneAnnotations(); List<AnnotationRuleViolation> allViolations = new ArrayList<AnnotationRuleViolation>(); for (GeneAnnotation annotation : annotations) { Set<AnnotationRuleViolation> violations = rule.getRuleViolations(annotation); if (violations != null && !violations.isEmpty()) { allViolations.addAll(violations); for (AnnotationRuleViolation violation : violations) { System.out.println(violation); } } } assertEquals(232, allViolations.size()); }