Skip to main content

Get selected sequence interval from a document



  • Richard Moir

    1) It depends where this code is. Do you have a new viewer and you want to get the selection from the sequence view? Or is it an operation or something else entirely?

    2) To add buttons to the built-in toolbar, override the method getActionProvider() in your DocumentViewer. Refer to the java doc on com.biomatters.geneious.publicapi.plugin.ActionProvider for  details on how this works. You will probably want to override the getOtherActions() method in ActionProvider.

  • ashok matte

    1) yes, I created a viewer based on the ExampleDocumentViewer. I would like to get the interval of the selected region from the sequence view. I was wondering how to get the start and end residue to extract the interval.

    2) getOtherActions() was exactly the method I was looking for, thanks.

    3) my documents consist of several different annotations, it takes time if I start clicking check boxes to enable/disable the visibility of particular annotations. I was thinking of grouping annotations which, on single click make them visible or invisible. I found api documentation of the sequence track. I think it can provide the possibility of grouping annotations.

    Normally, my code is
    List<SequenceAnnotation> results = new ArrayList<SequenceAnnotation>();
    final SequenceAnnotationInterval interval = new SequenceAnnotationInterval(startPos, stopPos);
    SequenceAnnotation gene_annotation = new SequenceAnnotation(label_anno,"Gene clusters",interval);

    gene_annotation.addQualifier(new SequenceAnnotationQualifier("cluster1",    ""));

    return Arrays.asList(results);
    This code works perfectly fine for me. I was a bit confused with SequenceTrack as it doesn't have the function to create  SequenceAnnotation. Is there a better way of grouping different annotation types?

    SequenceTrack track = new SequenceTrack("annotations on sequences");
    track.addQualifier(new SequenceAnnotationQualifier("genes found",   "");
    // no interval specified which gives a null exception
    SequenceTrack.Manager manager= new Manager(plugindocument); manager.addTrack(track);

    annotatedPluginDocument = DocumentUtilities.createAnnotatedPluginDocument(plugindocument); annotatedPluginDocument.saveDocument();


  • Richard Moir

    1) In that case you will need to listen for selection messages that the sequence viewer sends out whenever the selection changes. In your Viewer override the method getIncomingMessageHandler() and return a new DocumentViewerMessageHandler that implements the method setSequenceSelection(). This method will then be called whenever the sequence view (or any other view) changes the selection. Read the javadoc on DocumentViewerMessageHandler for more details.

    2) Great :)

    3) Tracks are the right thing to use i think. You should create the annotations in the normal way then use SequenceTrack.setAnnotations(List<SequenceAnnotation>) to put your annotations in the track. 

  • ashok matte

    Hi Richard,

    thanks, it was helpful.

    I was unable to add my annotations to a track. It results in plain sequence without any annotations. I think I'm missing something minor here. Is there a problem with my code in calling the module?

    I'm using it in DocumentFileImporter.

        SequenceTrack track = new SequenceTrack("Misc clusters");
        List<SequenceAnnotation> results = new ArrayList<SequenceAnnotation>();
        results.add(annotations); // adding annotations to sequenceannotation list
        SequenceTrack.Manager manager = new SequenceTrack.Manager((DefaultSequenceDocument)plugindocument);
        annotatedPluginDocument =  DocumentUtilities.createAnnotatedPluginDocument(plugindocument);


    Ashok Matte.

  • Richard Moir

    Instead of constructing a new track manager, you need to get the one from your sequence:



Please sign in to leave a comment.