GoNDAnnotationRule extends AbstractAnnotationRule { @Override public Set<AnnotationRuleViolation> getRuleViolations(GeneAnnotation a) { String evidence = a.getShortEvidence(); if (evidence != null && evidences.contains(evidence)) { String cls = a.getCls(); if (rootIds.contains(cls) == false) { AnnotationRuleViolation violation = new AnnotationRuleViolation(getRuleId(), message+", but was: "+cls, a, violationType); return Collections.singleton(violation); } List<String> referenceIds = a.getReferenceIds(); boolean hasRef = false; for (String referenceId : referenceIds) { if (ndXrefs.contains(referenceId)) { hasRef = true; break; } } if (hasRef == false) { AnnotationRuleViolation violation = new AnnotationRuleViolation(getRuleId(), "ND annotations to root require reference ID", a, ViolationType.Warning); return Collections.singleton(violation); } } else { String cls = a.getCls(); if (rootIds.contains(cls)) { AnnotationRuleViolation violation = new AnnotationRuleViolation(getRuleId(), message+", but was root node: "+cls+" with evidence code: "+evidence, a, violationType); return Collections.singleton(violation); } } return null; } GoNDAnnotationRule(TraversingEcoMapper eco); @Override Set<AnnotationRuleViolation> getRuleViolations(GeneAnnotation a); static final String PERMANENT_JAVA_ID; }
@Test public void test() throws Exception { GafDocument gafdoc = loadGaf("test_gene_association_mgi.gaf"); AnnotationRule rule = new GoNDAnnotationRule(eco); 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); } } assertEquals(1, allViolations.size()); }