GoMultipleTaxonRule extends AbstractAnnotationRule { @Override public Set<AnnotationRuleViolation> getRuleViolations(GeneAnnotation a) { String actsOnTaxonId = null; Pair<String, String> pair = a.getActsOnTaxonId(); if (pair != null) { actsOnTaxonId = pair.getLeft(); } if (actsOnTaxonId == null || actsOnTaxonId.isEmpty()) { return Collections.emptySet(); } final OWLClass tax2 = graph.getOWLClassByIdentifierNoAltIds(actsOnTaxonId); if (tax2 == null) { AnnotationRuleViolation v = new AnnotationRuleViolation(getRuleId(), "Could not retrieve a class for taxonCls: "+actsOnTaxonId, a, ViolationType.Warning); return Collections.singleton(v); } String annotationCls = a.getCls(); String taxonCls = a.getBioentityObject().getNcbiTaxonId(); if (taxonCls == null) { return Collections.emptySet(); } final OWLObject cls = graph.getOWLObjectByIdentifier(annotationCls); final OWLObject tax = graph.getOWLObjectByIdentifier(taxonCls); if (cls == null) { return Collections.emptySet(); } if (tax2.equals(tax) == false && multiOrganismClasses.contains(cls) == false) { AnnotationRuleViolation v = new AnnotationRuleViolation(getRuleId(), "While using dual taxons, multiple organism terms are required, but was: "+annotationCls, a, ViolationType.Warning); return Collections.singleton(v); } return Collections.emptySet(); } GoMultipleTaxonRule(OWLGraphWrapper graph); @Override Set<AnnotationRuleViolation> getRuleViolations(GeneAnnotation a); static final String PERMANENT_JAVA_ID; }
@Test public void test() throws Exception { GafDocument gafdoc = loadZippedGaf("gene_association.PAMGO_Mgrisea.gz"); AnnotationRule rule = new GoMultipleTaxonRule(graph); List<AnnotationRuleViolation> allViolations = new ArrayList<AnnotationRuleViolation>(); List<GeneAnnotation> annotations = gafdoc.getGeneAnnotations(); for (GeneAnnotation annotation : annotations) { Set<AnnotationRuleViolation> violations = rule.getRuleViolations(annotation); if (violations != null && !violations.isEmpty()) { allViolations.addAll(violations); } } assertEquals(89, allViolations.size()); }