Newer
Older
*
* created: 2013
*
* This file is part of Artemis
*
* Copyright(C) 2013 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or(at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package uk.ac.sanger.artemis.io;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Vector;
import javax.swing.JOptionPane;
import org.apache.log4j.Level;
import uk.ac.sanger.artemis.EntryGroup;
import uk.ac.sanger.artemis.Feature;
import uk.ac.sanger.artemis.FeatureKeyPredicate;
import uk.ac.sanger.artemis.FeatureKeyQualifierPredicate;
import uk.ac.sanger.artemis.FeaturePredicate;
import uk.ac.sanger.artemis.FeaturePredicateConjunction;
import uk.ac.sanger.artemis.FilteredEntryGroup;
import uk.ac.sanger.artemis.GotoEventSource;
import uk.ac.sanger.artemis.Options;
import uk.ac.sanger.artemis.Selection;
import uk.ac.sanger.artemis.components.BasePlotGroup;
import uk.ac.sanger.artemis.components.EntryFileDialog;
import uk.ac.sanger.artemis.components.FeatureListFrame;
import uk.ac.sanger.artemis.components.FileViewer;
import uk.ac.sanger.artemis.components.database.DatabaseEntrySource;
import uk.ac.sanger.artemis.components.genebuilder.GeneUtils;
import uk.ac.sanger.artemis.util.DatabaseDocument;
import uk.ac.sanger.artemis.util.Document;
import uk.ac.sanger.artemis.util.DocumentFactory;
import uk.ac.sanger.artemis.util.StringVector;
public class ValidateFeature
{
private static String[] geneModelParts;
//##sequence-region seqid start end
private static Pattern HEADER_SEQ_REGION = Pattern.compile("##sequence-region \\S+ \\d+ \\d+");
private static Pattern CAPITAL_START = Pattern.compile("^[A-Z]+\\S*");
private static Pattern ID_PREFIX = Pattern.compile("^[^.:]+");
private static String[] RESERVED_TAGS =
{ "ID", "Name", "Alias", "Parent",
"Target", "Gap", "Derives_from", "Note",
"Dbxref", "Ontology_term", "Is_circular",
"Start_range", "End_range"};
private static String[] OTHER_RESERVED_TAGS =
{ "GO", "EC_number", "EMBL_qualifier", "SignalP_prediction",
private static String[] ALLOWED_TAGS_WITH_NO_VALUE =
{ "stop_codon_redefined_as_selenocysteine", "Name" };
public ValidateFeature(EntryGroup entryGrp)
{
this.entryGrp = entryGrp;
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
}
public static void testHeader(final String headerTxt)
{
final BufferedReader reader = new BufferedReader(
new StringReader(headerTxt));
try
{
String str;
while ((str = reader.readLine()) != null)
{
if(str.startsWith("##sequence-region "))
{
if(!HEADER_SEQ_REGION.matcher(str).matches())
{
System.out.println("ERROR : HEADER "+str);
}
}
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
public void featureListErrors(final EntryGroup grp,
final Selection sel,
final GotoEventSource gotoSrc,
final BasePlotGroup plotGrp)
{
if(GeneUtils.isGFFEntry( grp ))
{
showFeatureList(ATTR_PREDICATE, "Attributes", grp, sel, gotoSrc, plotGrp);
showFeatureList(CDS_PHASE_PREDICATE, "CDS phase", grp, sel, gotoSrc, plotGrp);
showFeatureList(STRAND_PREDICATE, "Gene Strand Errors", grp, sel, gotoSrc, plotGrp);
showFeatureList(BOUNDARY_PREDICATE, "Gene Boundary Errors", grp, sel, gotoSrc, plotGrp);
showFeatureList(COMPLETE_GENE_MODEL_PREDICATE, "Incomplete Gene Model", grp, sel, gotoSrc, plotGrp);
showFeatureList(PARTIAL_PREDICATE, "Check Partial Settings", grp, sel, gotoSrc, plotGrp);
showFeatureList(ID_PREDICATE, "Check ID Settings", grp, sel, gotoSrc, plotGrp);
showFeatureList(INTERNAL_STOP, "Internal Stop Codons", grp, sel, gotoSrc, plotGrp);
showFeatureList(NO_VALID_STOP, "No Valid Stop Codons", grp, sel, gotoSrc, plotGrp);
final String title,
final EntryGroup grp,
final Selection sel,
final GotoEventSource gotoSrc,
final BasePlotGroup plotGrp)
{
final FilteredEntryGroup fltrGrp = new FilteredEntryGroup (grp, predicate, title);
if(fltrGrp.getAllFeaturesCount() < 1)
return;
final FeatureListFrame featureList =
new FeatureListFrame (title, sel, gotoSrc, fltrGrp, plotGrp);
featureList.setVisible(true);
}
* GFF - check complete gene model
* - check boundaries are valid
* - check all features are on the same strand
* - check CDS features have a phase
* - check attribute column
* - qualifiers have a value (not empty)
* - only reserved tags start with uppercase
* - CDS have no internal stop codon
* - CDS have valid stop codon
*
private LinkedHashMap<String, Level> featureValidate(final uk.ac.sanger.artemis.io.Feature f,
final LinkedHashMap<String, Level> report = new LinkedHashMap<String, Level>();
final String fTxt = featureTxt(f);
final boolean isGFF = entryGrp == null || GeneUtils.isGFFEntry( entryGrp );
report.put("\n"+GeneUtils.getUniqueName(gffFeature)+" ("+fTxt+"):", Level.INFO);
if(isPartOfGene(gffFeature))
{
int compl = isCompleteGeneModelOK(gffFeature);
switch (compl)
{
case 1: report.put("No gene found", Level.FATAL); pass = false; break;
case 2: report.put("Missing transcript", Level.FATAL); pass = false; break;
default: report.put("Gene model is complete", Level.INFO); break;
{
pass = false;
report.put(getGeneBoundaryMsg(gb), Level.FATAL);
}
{
pass = false;
report.put("Gene features found on different strand", Level.FATAL);
}
if(!isPartialConsistent(gffFeature, "Start_range") ||
!isPartialConsistent(gffFeature, "End_range"))
report.put("Partial settings not consistent", Level.FATAL);
if(!isIdPrefixConsistent(gffFeature))
{
pass = false;
report.put("Prefix of ID attribute not consistent within gene model", Level.FATAL);
}
if( (entryGrp == null || !GeneUtils.isDatabaseEntry(entryGrp)) && !isCDSPhaseOK(gffFeature))
{
pass = false;
report.put("CDS phase (codon_start) not set", Level.FATAL);
}
if(attr.endsWith("\n"))
attr = attr.substring(0, attr.length()-1);
report.put("\n"+((uk.ac.sanger.artemis.Feature)f.getUserData()).getIDString()+
" ("+fTxt+"):", Level.INFO);
{
pass = false;
report.put("Internal stop codon found", Level.FATAL);
}
final EntryInformation eInfo;
if(f.getEntry() == null)
eInfo = ((Feature)f.getUserData()).getEntry().getEntryInformation();
else
eInfo = f.getEntry().getEntryInformation();
// test GO qualifier
final String goErrMsg;
if((goErrMsg = validateGO(f.getQualifiers(), eInfo)).length() > 0)
{
pass = false;
report.put(goErrMsg, Level.FATAL);
}
{
pass = false;
report.put("No valid stop codon found", Level.FATAL);
}
if(pass)
}
return report;
}
/**
* Check a single feature and append validation report to the
* viewer.
* @return true if successfully validate
*/
public boolean featureValidate(final uk.ac.sanger.artemis.io.Feature f,
final FileViewer fv,
final boolean showFailedFeaturesOnly)
{
final LinkedHashMap<String, Level> report = featureValidate(f, showFailedFeaturesOnly);
boolean pass = false;
if (report != null)
{
if (!showFailedFeaturesOnly && entry.getKey().equals("PASS"))
pass = true;
fv.appendString(entry.getKey() + "\n", entry.getValue());
}
/**
* Check GO annotation for:
* 1) unexpected white space in with/from and dbxref columns
* 2) with/from must be empty when using IDA, NAS, ND, TAS or EXP evidence code
* 3) GO:0005515 can only have IPI evidence code
* 4) IEP is not allowed for molecular_function and cellular_component terms
* 5) with field must be filled when using ISS, ISA, ISO and ISM codes.
* @param qualifiers
* @param eInfo
* @return errors found in GO annotation
*/
public static String validateGO(QualifierVector qualifiers, EntryInformation eInfo)
{
final StringBuilder buff = new StringBuilder();
final Qualifier q = qualifiers.getQualifierByName("GO");
if (q != null)
{
try
{
final QualifierInfo qI = eInfo.getQualifierInfo("GO");
final StringVector qualifierStrs = StreamQualifier.toStringVector(qI,q);
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
{
final String code = getEvidenceCodeAbbreviation(qualifierStr);
final String goid = getField("GOid=", qualifierStr);
final String with = getField("with=", qualifierStr);
final String dbxref = getField("dbxref=", qualifierStr);
// System.err.println(GeneUtils.getUniqueName(f)+" "+code+" "+qualifierStr);
if (code != null)
{
if (code.equals("IDA") || code.equals("NAS") || code.equals("ND") ||
code.equals("TAS") || code.equals("EXP"))
{
// with/from must be empty
if (with.length() > 0)
buff.append("GOid=" + goid
+ ", the with/from must be empty when using " + code + "\n");
}
else if (code.equals("ISS") || code.equals("ISA") ||
code.equals("ISO") || code.equals("ISM"))
{
// with field must be filled
if (with.length() == 0)
buff.append("GOid=" + goid +
", the with/from field must be filled when using " + code + "\n");
}
}
// GO:0005515 can only have IPI evidence code
if (goid.equals("GO:0005515") && (code == null || !code.equals("IPI")))
buff.append("GOid=" + goid + ", can only have IPI evidence code\n");
// IEP is not allowed for molecular_function and cellular_component terms
if (code != null && code.equals("IEP")
&& !getField("aspect=", qualifierStr).equals("P"))
buff.append("GOid=" + goid + ", IEP is restricted to Biological Process terms\n");
if (with.indexOf(" ") > -1 || dbxref.indexOf(" ") > -1)
{
buff.append("GOid=" + goid + ", ");
if (with.indexOf(" ") > -1)
buff.append("with/from field (" + with + ") contains white space ");
if (dbxref.indexOf(" ") > -1)
buff.append("dbxref field (" + dbxref + ") contains white space");
buff.append("\n");
}
}
} catch(Exception e){}
}
return buff.toString();
}
/**
* Extract the value of a field from a qualifier string
* @param fieldName
* @param qualifierString
* @return
*/
private static String getField(final String fieldName, final String qualifierStr)
{
String field = "";
int ind1 = qualifierStr.toLowerCase().indexOf(fieldName.toLowerCase());
int ind2 = qualifierStr.indexOf(";", ind1);
int len = fieldName.length();
if(ind2 > ind1 && ind1 > -1)
field = qualifierStr.substring(ind1+len,ind2);
else if(ind1 > -1)
field = qualifierStr.substring(ind1+len);
if(field.endsWith("\""))
field = field.substring(0, field.length()-1);
if(field.startsWith("\""))
field = field.substring(1);
return field;
}
private static String getEvidenceCodeAbbreviation(String goText)
{
final String evidence = getField("evidence=", goText);
for(int i=0; i<GoBox.evidenceCodes[2].length; i++)
if(GoBox.evidenceCodes[2][i].equalsIgnoreCase(evidence))
return GoBox.evidenceCodes[0][i];
for(int i=0; i<GoBox.evidenceCodes[0].length; i++)
if(GoBox.evidenceCodes[0][i].equalsIgnoreCase(evidence))
return GoBox.evidenceCodes[0][i];
return null;
}
/**
* Check if the gene model is complete
* @param gffFeature
* @return 0 - complete gene model
* 1 - no gene found
* 2 - missing transcript
*/
private static int isCompleteGeneModelOK(final GFFStreamFeature gffFeature)
{
final ChadoCanonicalGene gene = gffFeature.getChadoGene();
if(gene == null)
return 1;
final List<uk.ac.sanger.artemis.io.Feature> transcripts = gene.getTranscripts();
if(transcripts.size() < 1)
return 2;
return 0;
}
private static int isBoundaryOK(final GFFStreamFeature gffFeature)
{
final ChadoCanonicalGene gene = gffFeature.getChadoGene();
int gb = 0;
if(gene != null && isGene(gffFeature))
gb = GeneUtils.isBoundaryOK(gene);
return gb;
}
private static boolean isStrandOK(final GFFStreamFeature gffFeature)
{
final ChadoCanonicalGene gene = gffFeature.getChadoGene();
if(gene != null && isGene(gffFeature) && !GeneUtils.isStrandOK(gene))
return false;
return true;
}
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
/**
* Test if the partial qualifiers are consistent within a gene model
* @param gffFeature
* @param partialKeyStr - either Start_range or End_range qualifier keys
* @return
*/
private static boolean isPartialConsistent(final GFFStreamFeature gffFeature,
final String partialKeyStr)
{
final ChadoCanonicalGene gene = gffFeature.getChadoGene();
if(gene == null)
return true;
try
{
// is the gene marked as partial
boolean partial =
(gene.getGene().getQualifierByName(partialKeyStr) == null ? false : true);
if(partial)
{
if(!isPartialChildren(partial, gene, gene.getGene(), partialKeyStr))
return false;
}
else
{
final List<uk.ac.sanger.artemis.io.Feature> transcripts = gene.getTranscripts();
for(uk.ac.sanger.artemis.io.Feature f: transcripts)
{
// is the transcript marked as partial
partial = (f.getQualifierByName(partialKeyStr) == null ? false : true);
if(!isPartialChildren(partial, gene, f, partialKeyStr))
return false;
}
}
}
catch (Exception e){ e.printStackTrace(); }
return true;
}
/**
* Return true if the child features agree with the parent
* feature for a given key
* @param parentIsPartial
* @param gene
* @param f
* @param partialKeyStr
* @return
* @throws InvalidRelationException
*/
private static boolean isPartialChildren(
final boolean parentIsPartial,
final ChadoCanonicalGene gene,
final uk.ac.sanger.artemis.io.Feature f,
final String partialKeyStr) throws InvalidRelationException
{
final Set<uk.ac.sanger.artemis.io.Feature> children = gene.getChildren(f);
for(uk.ac.sanger.artemis.io.Feature child: children)
{
String keyStr = child.getKey().getKeyString();
boolean isComplement = f.getLocation().isComplement();
if(keyStr.equals("three_prime_UTR"))
{
if(isComplement)
{
if(partialKeyStr.equals("End_range"))
continue;
}
else
{
if(partialKeyStr.equals("Start_range"))
continue;
}
}
else if(keyStr.equals("five_prime_UTR"))
{
if(isComplement)
{
if(partialKeyStr.equals("Start_range"))
continue;
}
else
{
if(partialKeyStr.equals("End_range"))
continue;
}
}
boolean partial = (child.getQualifierByName(partialKeyStr) == null ? false : true);
if( ( partial && !parentIsPartial ) ||
( !partial && parentIsPartial ) )
return false;
}
return true;
}
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
/**
* Test if the ID GFF3 attribute prefix is consistent within a gene model
* @param gffFeature
* @return true if the prefix is the same within the gene model features
*/
private static boolean isIdPrefixConsistent(final GFFStreamFeature gffFeature)
{
final ChadoCanonicalGene gene = gffFeature.getChadoGene();
if(gene == null)
return true;
try
{
if(gffFeature.getKey().getKeyString().endsWith("gene"))
return (gene.getGene().getQualifierByName("ID") != null);
if(gene.getGene().getQualifierByName("ID") == null)
return true;
if(gffFeature.getQualifierByName("ID") == null)
return false;
String id = gene.getGene().getQualifierByName("ID").getValues().elementAt(0);
final Matcher m = ID_PREFIX.matcher(id);
if(m.matches())
{
id = gffFeature.getQualifierByName("ID").getValues().elementAt(0);
return id.startsWith( m.group() );
}
}
catch (Exception e)
{
e.printStackTrace();
}
return true;
}
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
/**
* The phase is REQUIRED for all CDS features.
* @param gffFeature
*/
public static boolean isCDSPhaseOK(final GFFStreamFeature gffFeature)
{
if(!gffFeature.getKey().getKeyString().equals("CDS"))
return true;
final Qualifier codonStart = gffFeature.getQualifierByName("codon_start");
if(codonStart == null)
return false;
return true;
}
/**
* Check attribute column
* @param gffFeature
*/
public static String isAttributesOK(final GFFStreamFeature gffFeature)
{
final StringBuilder str = new StringBuilder();
final QualifierVector qualifiers = gffFeature.getQualifiers();
for(Qualifier qualifier: qualifiers)
{
if(CAPITAL_START.matcher(qualifier.getName()).matches())
{
boolean found = false;
for(String r: RESERVED_TAGS)
if(qualifier.getName().equals(r))
found = true;
for(String r: OTHER_RESERVED_TAGS)
if(qualifier.getName().equals(r))
found = true;
if(!found)
{
String msg = qualifier.getName()+" non-reserved attribute name begins with uppercase\n";
str.append(msg);
}
}
// check format tag=value
final StringVector values = qualifier.getValues();
if( values == null || values.size() < 1 ||
( values.size() == 1 && values.get(0).equals("")) )
{
boolean allowed = false;
if(GeneUtils.isDatabaseEntry(gffFeature))
{
for(String a: ALLOWED_TAGS_WITH_NO_VALUE)
if(qualifier.getName().equals(a))
allowed = true;
}
if(!allowed)
{
String msg = qualifier.getName()+" atribute has no value\n";
str.append(msg);
}
return str.toString();
}
public boolean isInternalStops(final uk.ac.sanger.artemis.io.Feature feature)
final uk.ac.sanger.artemis.Feature f = (uk.ac.sanger.artemis.Feature) feature.getUserData();
final AminoAcidSequence aa = f.getTranslation ();
return aa.containsStopCodon ();
}
public boolean hasValidStop(final uk.ac.sanger.artemis.io.Feature feature)
{
final uk.ac.sanger.artemis.Feature f = (uk.ac.sanger.artemis.Feature) feature.getUserData();
if(!cds_predicate.testPredicate (f))
return true;
return f.hasValidStopCodon (true);
}
if(entryGrp != null && GeneUtils.isDatabaseEntry( entryGrp ))
{
final FeaturePredicate codingPredicate = new FeaturePredicate(){
private String nonCodingTranscripts[] = GeneUtils.getNonCodingTranscripts();
public boolean testPredicate(Feature feature)
{
try
{
final GFFStreamFeature gffF = (GFFStreamFeature)feature.getEmblFeature();
final ChadoCanonicalGene chadoGene = gffF.getChadoGene();
if(chadoGene != null)
{
uk.ac.sanger.artemis.io.Feature transcriptF =
chadoGene.getTranscriptFeatureFromName(GeneUtils.getUniqueName(gffF));
final String transcriptKey = transcriptF.getKey().getKeyString();
for(int i=0; i<nonCodingTranscripts.length; i++)
if(nonCodingTranscripts[i].equals(transcriptKey))
return false;
}
}
catch(Exception e){}
return true;
};
};
cds_predicate =
new FeaturePredicateConjunction(
new FeatureKeyPredicate(new Key(DatabaseDocument.EXONMODEL)),
codingPredicate,
FeaturePredicateConjunction.AND);
}
else
cds_predicate =
new FeaturePredicateConjunction(
new FeatureKeyQualifierPredicate(Key.CDS, "pseudo", false),
new FeatureKeyQualifierPredicate(Key.CDS, "pseudogene", false),
FeaturePredicateConjunction.AND);
return cds_predicate;
}
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
private static String getGeneBoundaryMsg(int gb)
{
String msg = "Valid gene boundary";
switch(gb)
{
case 1: msg = "Transcript start or end is outside gene range";
break;
case 2: msg = "Child feature of a transcript is outside the transcript range";
break;
case 3: msg = "Span of the children features does not match start and end of the transcript";
break;
case 4: msg = "Protein range does not match CDS";
break;
case 5: msg = "Gene range does not match the largest transcript range";
break;
}
return msg;
}
private static boolean isPartOfGene(final GFFStreamFeature gffFeature)
{
final String keyStr = gffFeature.getKey().getKeyString();
for(String part: getGeneModelParts())
if( part.equals(keyStr) )
return true;
return false;
}
private static boolean isGene(final GFFStreamFeature gffFeature)
{
final String keyStr = gffFeature.getKey().getKeyString();
return keyStr.equals("gene") || keyStr.equals("pseudogene");
}
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
private String featureTxt(final uk.ac.sanger.artemis.io.Feature f)
{
final Feature feature = (Feature) (f.getUserData());
if(feature == null)
return f.getLocation().toStringShort();
final Marker low_marker = feature.getFirstBaseMarker();
final Marker high_marker = feature.getLastBaseMarker();
String low_pos, high_pos;
if(low_marker == null || high_marker == null)
{
low_pos = "unknown";
high_pos = "unknown";
}
else
{
if(low_marker.getRawPosition() < high_marker.getRawPosition())
{
low_pos = String.valueOf(low_marker.getRawPosition());
high_pos = String.valueOf(high_marker.getRawPosition());
}
else
{
low_pos = String.valueOf(high_marker.getRawPosition());
high_pos = String.valueOf(low_marker.getRawPosition());
}
}
if(GeneUtils.isDatabaseEntry(entryGrp))
{
try
{
if(feature.getQualifierByName("Start_range") != null)
if(feature.getQualifierByName("End_range") != null)
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
high_pos = ">"+high_pos;
}
catch (InvalidRelationException e){}
}
else
{
if(feature.getLocation().isPartial(true)) // 5prime
{
if(feature.isForwardFeature())
low_pos = "<"+low_pos;
else
high_pos = ">"+high_pos;
}
if(feature.getLocation().isPartial(false)) // 3prime
{
if(feature.isForwardFeature())
high_pos = ">"+high_pos;
else
low_pos = "<"+low_pos;
}
}
final StringBuilder txt = new StringBuilder();
txt.append(feature.getKey().getKeyString()).append(" ");
txt.append(low_pos).append("..").append(high_pos);
if(!feature.isForwardFeature())
txt.append(" c");
return txt.toString();
}
private static String[] getGeneModelParts()
{
if(geneModelParts != null)
return geneModelParts;
final String[] geneModelKeys = {
"gene", "transcript", "mRNA", "CDS", "exon", "polypeptide", "three_prime_UTR", "five_prime_UTR",
"pseudogene", "pseudogenic_transcript", "pseudogenic_exon" };
final String[] ncTranscripts = GeneUtils.getNonCodingTranscripts();
geneModelParts = new String[
geneModelKeys.length+ncTranscripts.length];
for(int i=0; i<geneModelKeys.length; i++)
geneModelParts[i] = geneModelKeys[i];
for(int i=0; i<ncTranscripts.length; i++)
geneModelParts[i+geneModelKeys.length] = ncTranscripts[i];
return geneModelParts;
}
/**
* Open a panel with the validation results
* @param entry
* @param seq
*/
private void showReport(final Entry entry, final String seq)
{
final FeatureVector features = entry.getAllFeatures();
final FileViewer fv = new FileViewer("Validation Report :: "+seq+" "+
features.size()+" feature(s)", false, false, true);
int nfail = 0;
for(uk.ac.sanger.artemis.io.Feature f: features)
{
if(!featureValidate(f, fv, true))
nfail++;
}
fv.setTitle(fv.getTitle()+" Fails:"+nfail);
fv.setVisible(true);
}
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
/**
* Write the validation results to a file
* @param writer
* @param entry
* @param seq
*/
private void writeReport(final BufferedWriter writer, final Entry entry, final String seq)
{
final FeatureVector features = entry.getAllFeatures();
try
{
for(uk.ac.sanger.artemis.io.Feature f: features)
{
LinkedHashMap<String, Level> report = featureValidate(f, true);
if (report != null)
{
for (Map.Entry<String, Level> ent : report.entrySet())
{
writer.append(ent.getKey());
writer.newLine();
}
}
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
private static FeaturePredicate ATTR_PREDICATE = new FeaturePredicate()
{
public boolean testPredicate(uk.ac.sanger.artemis.Feature feature)
{
return isAttributesOK((GFFStreamFeature) feature.getEmblFeature()).length() > 0;
}
};
private static FeaturePredicate CDS_PHASE_PREDICATE = new FeaturePredicate()
{
public boolean testPredicate(uk.ac.sanger.artemis.Feature feature)
{
return !isCDSPhaseOK((GFFStreamFeature) feature.getEmblFeature());
}
};
private static FeaturePredicate STRAND_PREDICATE = new FeaturePredicate()
{
public boolean testPredicate(uk.ac.sanger.artemis.Feature feature)
{
return !isStrandOK((GFFStreamFeature) feature.getEmblFeature());
}
};
private static FeaturePredicate BOUNDARY_PREDICATE = new FeaturePredicate()
{
public boolean testPredicate(uk.ac.sanger.artemis.Feature feature)
{
return isBoundaryOK((GFFStreamFeature) feature.getEmblFeature()) > 0;
}
};
private static FeaturePredicate COMPLETE_GENE_MODEL_PREDICATE = new FeaturePredicate()
{
public boolean testPredicate(uk.ac.sanger.artemis.Feature feature)
{
if(!isPartOfGene((GFFStreamFeature) feature.getEmblFeature()))
return false;
return isCompleteGeneModelOK((GFFStreamFeature) feature.getEmblFeature()) > 0;
}
};
private static FeaturePredicate PARTIAL_PREDICATE = new FeaturePredicate()
{
public boolean testPredicate(uk.ac.sanger.artemis.Feature feature)
{
if( isPartialConsistent((GFFStreamFeature) feature.getEmblFeature(), "Start_range") &&
isPartialConsistent((GFFStreamFeature) feature.getEmblFeature(), "End_range") )
return false;
return true;
}
};
private static FeaturePredicate ID_PREDICATE = new FeaturePredicate()
{
public boolean testPredicate(uk.ac.sanger.artemis.Feature feature)
{
if( isIdPrefixConsistent((GFFStreamFeature) feature.getEmblFeature() ))
return false;
return true;
}
};
private FeaturePredicate INTERNAL_STOP = new FeaturePredicate()
{
public boolean testPredicate(uk.ac.sanger.artemis.Feature feature)
{
return isInternalStops(feature.getEmblFeature());
}
};
private FeaturePredicate NO_VALID_STOP = new FeaturePredicate()
{
public boolean testPredicate(uk.ac.sanger.artemis.Feature feature)
{
return !hasValidStop(feature.getEmblFeature());
}
};
public static void main(final String args[])
{
if( (args != null && args.length == 1 && args[0].startsWith("-h")) ||
(args == null || args.length < 1))
System.out.println("Artemis validation options:");
System.out.println("-h\tshow help");
System.out.println("-s\tspace separated list of sequences to read and write out");
System.out.println("-c\tthe URL for your Chado database e.g. db.genedb.org:5432/snapshot?genedb_ro");
System.out.println("-o\twrite report to specified file");
System.exit(0);
}
BufferedWriter outfile = null;
for(int i = 0; i < args.length; i++)