BasicChecksRule extends AbstractAnnotationRule { @Override public Set<AnnotationRuleViolation> getRuleViolations(GeneAnnotation a) { Set<AnnotationRuleViolation> set = new HashSet<AnnotationRuleViolation>(); BufferedGafWriter gafWriter = new BufferedGafWriter(); gafWriter.write(a); List<String> lines = gafWriter.getLines(); if (lines.size() != 1) { AnnotationRuleViolation v = new AnnotationRuleViolation(PERMANENT_JAVA_ID, "Could not run basic check for annotation.", a); set.add(v); return set; } final String row = lines.get(0); final String cols[] = row.split("\\t", -1); checkCardinality(cols[0],0, "Column 1: DB", row,1,1, set,a); checkCardinality(cols[1], 1,"Column 2: DB Object ID", row,1,1, set,a); checkCardinality(cols[2], 2,"Column 3: DB Object Symbol", row,1,1, set,a); checkCardinality(cols[3], 3,"Column 4: Qualifier", row, 0, 3, set,a); checkCardinality(cols[4], 4,"Column 5: GO ID", row,1,1, set,a); checkCardinality(cols[5], 5,"Column 6: DB Reference", row,1,3, set,a); checkCardinality(cols[6], 6,"Column 7: Evidence Code", row,1,3, set,a); checkCardinality(cols[7], 7,"Column 8: With or From", row,0,3, set,a); checkCardinality(cols[9], 9,"Column 10: DB Object Name", row,0,1, set,a); checkCardinality(cols[10], 10,"Column 11: DB Object Synonym", row, 0,3, set,a); checkCardinality(cols[11], 11,"Column 12: DB Object Type", row, 1,1, set,a); checkCardinality(cols[12], 12,"Column 13: Taxon", row, 1,2, set,a); checkCardinality(cols[13], 13,"Column 14: Date", row, 1,1, set,a); checkCardinality(cols[14], 14,"Column 15: DB Object Type", row, 1,1, set,a); if(cols.length>15){ checkCardinality(cols[15], 15,"Column 16: DB Object Type", row, 0,3, set,a); if (cols.length>16) { checkCardinality(cols[16], 16,"Column 17: DB Object Type", row, 0,3, set,a); } } String dtString = cols[GAFParser.DATE]; try{ Date annotationDate = dtFormat.get().parse(dtString); if (ieaCodes.contains(a.getShortEvidence())) { Calendar todayMinusOneYear = Calendar.getInstance(); todayMinusOneYear.add(Calendar.YEAR, -1); Date time = todayMinusOneYear.getTime(); if (annotationDate.before(time)) { AnnotationRuleViolation v = new AnnotationRuleViolation(getRuleId(), "IEA evidence code present with a date more than a year old '"+dtString+"'" , a, ViolationType.Error); set.add(v); } } }catch(Exception ex){ AnnotationRuleViolation v = new AnnotationRuleViolation(getRuleId(), "The date in the column 14 is of incorrect format in the row: " , a); set.add(v); } String[] taxons = cols[GAFParser.TAXON].split("\\|"); checkTaxon(taxons[0], row, set,a); if(taxons.length>1){ checkTaxon(taxons[1], row, set,a); } if(!db_abbreviations.contains(cols[0])){ AnnotationRuleViolation v= new AnnotationRuleViolation(getRuleId(), "The DB '" + cols[0] + "' referred in the column 1 is incorrect in the row: " , a); set.add(v); } List<List<ExtensionExpression>> groupedExpressions = a.getExtensionExpressions(); if (groupedExpressions != null && !groupedExpressions.isEmpty()) { for (List<ExtensionExpression> expressions : groupedExpressions) { if (expressions != null && !expressions.isEmpty()) { for (ExtensionExpression extensionExpression : expressions) { String cls = extensionExpression.getCls(); int dbSepPos = cls.indexOf(':'); if (dbSepPos <= 0) { AnnotationRuleViolation v= new AnnotationRuleViolation(getRuleId(), "All identifiers in column 16 need a prefix. The id '" + cls + "' has no prefix. " , a); set.add(v); } } } } } return set; } BasicChecksRule(String xrefAbbsLocation, TraversingEcoMapper eco); @Override Set<AnnotationRuleViolation> getRuleViolations(GeneAnnotation a); static final String PERMANENT_JAVA_ID; static final ThreadLocal<SimpleDateFormat> dtFormat; }
@Test public void testOutdatedIEAs() throws Exception { GafDocument gafdoc = loadGaf("test_out_dated_iea.gaf"); 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()); AnnotationRuleViolation violation = allViolations.get(0); String message = violation.getMessage(); assertTrue(message.contains("IEA evidence code present with a date more than a year old")); }
@Test public void testMissingPrefixForC16() throws Exception { GafDocument gafdoc = loadGaf("id_prefix_c16_valid.gaf"); List<GeneAnnotation> validAnnotations = gafdoc.getGeneAnnotations(); assertEquals(1, validAnnotations.size()); Set<AnnotationRuleViolation> ruleViolations = rule.getRuleViolations(validAnnotations.get(0)); assertTrue(ruleViolations.isEmpty()); gafdoc = loadGaf("id_prefix_c16_invalid.gaf"); List<GeneAnnotation> inValidAnnotations = gafdoc.getGeneAnnotations(); assertEquals(1, inValidAnnotations.size()); ruleViolations = rule.getRuleViolations(inValidAnnotations.get(0)); assertEquals(1, ruleViolations.size()); AnnotationRuleViolation violation = ruleViolations.iterator().next(); final String message = violation.getMessage(); assertTrue(message.contains("The id 'SPCC1682.02c' has no prefix.")); }
@Test public void testMultipleTaxon() throws Exception { GafDocument gafdoc = loadGaf("rgd_multiple_taxon.gaf"); List<GeneAnnotation> validAnnotations = gafdoc.getGeneAnnotations(); assertEquals(1, validAnnotations.size()); Set<AnnotationRuleViolation> ruleViolations = rule.getRuleViolations(validAnnotations.get(0)); assertTrue(ruleViolations.isEmpty()); }