Class SequenceAnnotationGenerator


  • public abstract class SequenceAnnotationGenerator
    extends java.lang.Object
    A SequenceAnnotationGenerator generates annotations on a sequence, set of sequences, or an alignment. Despite its name, a SequenceAnnotationGenerator can also remove annotations, insert/delete/modify residues in a sequence and can modify document field values and notes.

    Currently, all SequenceAnnotationGenerators are made available from within the SequenceViewer 'Annotated & Predict' drop down menu.

    A plugin may provide a set of sequence annotation generators via GeneiousPlugin.getSequenceAnnotationGenerators().

    Here is an example of a SequenceAnnotationGenerator the implements a simple motif finder.

     public class ExampleSequenceAnnotationGenerator extends SequenceAnnotationGenerator {
        public GeneiousActionOptions getActionOptions() {
            return new GeneiousActionOptions("Example Find Motif",
                    "Finds a non-ambiguous motif and creates annotations covering each occurance").
                    setMainMenuLocation(GeneiousActionOptions.MainMenu.Sequence);
        }
    
        public String getHelp() {
            return "This plugin shows how to create a simple SequenceAnnotationGenerator by providing a simple implemenation of a Motif finder.";
        }
    
        public Options getOptions(AnnotatedPluginDocument[] documents, SelectionRange selectionRange) throws DocumentOperationException {
            return new ExampleSequenceAnnotationGeneratorOptions(); // Provides all the options we display to the user. See ExampleSequenceAnnotationGeneratorOptions below for details.
        }
    
        public DocumentSelectionSignature[] getSelectionSignatures() {
            return new DocumentSelectionSignature[] {
                    new DocumentSelectionSignature(NucleotideSequenceDocument.class,1,1)
                    // This indicates this annotation generator will accept a single nucleotide sequence as input
            };
        }
    
        public List<List<SequenceAnnotation>> generateAnnotations(AnnotatedPluginDocument[] annotatedPluginDocuments, SelectionRange selectionRange, ProgressListener progressListener, Options _options) throws DocumentOperationException {
            NucleotideSequenceDocument sequence= (NucleotideSequenceDocument) annotatedPluginDocuments[0].getDocument();
            // We can safely access the first element from the array since our selection signature specifies we accept 1 and only 1 document.
            // And we can safely cast it to a NucleotideSequenceDocument as the selection signature specified that too.
    
            ExampleSequenceAnnotationGeneratorOptions options = (ExampleSequenceAnnotationGeneratorOptions) _options;
            // We can safely cast this to ExampleSequenceAnnotationGeneratorOptions because that is all we ever return from getOptions()
    
            String sequenceString=sequence.getSequenceString().toUpperCase();
    
            List<SequenceAnnotation> results = new ArrayList<SequenceAnnotation>();
            String basesToFind=options.getBasesToFind();
            if (basesToFind.length()==0) {
                throw new DocumentOperationException("Must specify at least 1 base to find");
            }
    
            int indexToSearchFrom=0;
            int foundIndex;
            while((foundIndex=sequenceString.indexOf(basesToFind, indexToSearchFrom))>=0) {
                final SequenceAnnotationInterval interval = new SequenceAnnotationInterval(foundIndex + 1, foundIndex + basesToFind.length());
                SequenceAnnotation annotation=new SequenceAnnotation(options.getAnnotationName(),options.getAnnotationType(),interval);
                results.add(annotation);
                indexToSearchFrom=foundIndex+1;
            }
    
            if (options.isAlsoFindReverse()) {
                String reversedSequenceString = SequenceUtilities.reverseComplement(sequenceString).toString();
                indexToSearchFrom = 0;
                while((foundIndex=reversedSequenceString.indexOf(basesToFind, indexToSearchFrom))>=0) {
                    final SequenceAnnotationInterval interval = new SequenceAnnotationInterval(sequenceString.length()-foundIndex, sequenceString.length()-foundIndex - basesToFind.length()+1);
                    SequenceAnnotation annotation=new SequenceAnnotation(options.getAnnotationName(),options.getAnnotationType(),interval);
                    results.add(annotation);
                    indexToSearchFrom=foundIndex+1;
                }
            }
    
            return Arrays.asList(results); // Put the results in a single element array since we only operate on a single sequence hence there is only 1 set of results.
        }
    
        private static class ExampleSequenceAnnotationGeneratorOptions extends Options {
            private final BooleanOption alsoFindReverse;
            private final StringOption basesToFind;
            private final StringOption annotationType;
            private final StringOption annotationName;
            private ExampleSequenceAnnotationGeneratorOptions() {
                basesToFind = addStringOption("basesToFind","Bases to find","");
                alsoFindReverse = addBooleanOption("alsoFindReverse", "Also find on reverse complement", true);
    
                annotationType = addStringOption("annotationType","Annotation type", SequenceAnnotation.TYPE_MOTIF);
                annotationType.setAdvanced(true);
                annotationType.setDescription("The type of annotations that will be created on each matching occurnace");
    
                annotationName = addStringOption("annotationName","Annotation name", "");
                annotationName.setAdvanced(true);
                annotationName.setDescription("The name of the annotations that will be created on each matching occurnace");
            }
    
            public boolean isAlsoFindReverse() {
                return alsoFindReverse.getValue();
            }
    
            public String getBasesToFind() {
                return basesToFind.getValue().toUpperCase();
            }
    
            public String getAnnotationType() {
                return annotationType.getValue();
            }
    
            public String getAnnotationName() {
                return annotationName.getValue();
            }
    
        }
    }
     
    For more advanced usage, such as deleting annotations, or modifiying bases/residues, implement generate(com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument[], com.biomatters.geneious.publicapi.plugin.SequenceAnnotationGenerator.SelectionRange, jebl.util.ProgressListener, Options).