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.
-
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.
0 -
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.
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 exceptionSequenceTrack.Manager manager= new Manager(plugindocument); manager.addTrack(track);
annotatedPluginDocument = DocumentUtilities.createAnnotatedPluginDocument(plugindocument); annotatedPluginDocument.saveDocument();
regards,
Ashok0 -
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.
0 -
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.
0 -
Instead of constructing a new track manager, you need to get the one from your sequence:
((DefaultSequenceDocument)pluginDocument).getTrackManager(false).addTrack(track)
0
Please sign in to leave a comment.
Comments
5 comments