Post

2 followers Follow
0
Avatar

Get selected sequence interval from a document

Hi,

I'm trying to get the interval of the selected sequence of a document. 

SequenceSelection.SequenceIndex selection_index = new SequenceSelection.SequenceIndex(0, SequenceType.NUCLEOTIDE, SequenceSelection.SequenceDocumentType.Sequence);


SequenceSelection.SelectionInterval selection_interval= new SequenceSelection.SelectionInterval(selection_index, start_residue, end_residue);

 

How can I get the start residue and end residue form the document?

 

I'm also trying to add a toolbar to my viewer. I already added JToolbar which is taking extra space on the top of JPanel, but if it is possible I would like to add it to the empty space  between JPanel and viewer tab name where usual geneious options exsists. 

 

Is there a way to solve this problem?

(a little bit of sample code would be helpful)

 

 

Regards,

Ashok.

ashok matte

Please sign in to leave a comment.

5 comments

0
Avatar

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.

Richard Moir 0 votes
Comment actions Permalink
0
Avatar
Hi,


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",    ""));

results.add(gene_annotation);
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();



regards,
Ashok

ashok matte 0 votes
Comment actions Permalink
0
Avatar

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. 

Richard Moir 0 votes
Comment actions Permalink
0
Avatar

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
    track.setAnnotations(results);
    SequenceTrack.Manager manager = new SequenceTrack.Manager((DefaultSequenceDocument)plugindocument);
    manager.addTrack(track);
    annotatedPluginDocument =  DocumentUtilities.createAnnotatedPluginDocument(plugindocument);
    callback.addDocument(annotatedPluginDocument);



Regards,

Ashok Matte.

ashok matte 0 votes
Comment actions Permalink
0
Avatar

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

((DefaultSequenceDocument)pluginDocument).getTrackManager(false).addTrack(track)

Richard Moir 0 votes
Comment actions Permalink