Getting plasmid Genbank files programmatically
I am trying to create a Geneious plugin that takes a selected group of plasmids and sends their corresponding Genbank files to an API, but I cannot figure out how to do this programmatically. It needs to be done programmatically because it's a multi-step and error-prone process using the GUI. Also, I am not trying to submit to Genbank programmatically; I am trying to submit the Genbank files to an API my company uses in-house.
This is what I've been able to figure out so far extending a GeneiousService:
public JPanel getServiceComponent() {
JPanel panel = new JPanel();
JButton button = new JButton("Export Selected to Service");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<AnnotatedPluginDocument> selectedDocs = DocumentUtilities.getSelectedDocuments();
List<byte[]> genbankData = new ArrayList<>();
for (AnnotatedPluginDocument doc : selectedDocs) {
if (doc.getDocumentClass() == NucleotideSequenceDocument.class) {
try {
// This is the part I can't figure out
} catch (Exception ex) {
JOptionPane.showMessageDialog(panel, "Failed to export " + doc.getName() + ": " + ex.getMessage());
}
}
}
}
});
panel.add(button);
return panel;
}
But I can't figure out the rest, despite looking at the API docs and tutorials. Can someone give me some guidance, please?
-
Official comment
Hi, you can get an exporter for GenBank File Format using this command:
DocumentFileExporter genbankExporter = PluginUtilities.getDocumentFileExporter("com.biomatters.plugins.ncbi.importexport.genbankflatexporter.GenBankFlatExporter");
if (genbankExporter != null) { \\ If the plugin is disabled this might be null
Options exportOptions = genbankExporter.getOptions(annotatedPluginDocumentList);
genbankExporter.export(fileToExportTo, myNucleotideDocuments, ProgressListener.EMPTY, exportOptions);
}Then you would need to get the content of `fileToExportTo` and pass it to your API.
If you don't need the actual file after that, you can use
FileUtilities.createTempFile(...)
For your second question about `getSelectedDocuments()` being empty, that sounds like something is going wrong, it should not be empty if you have documents selected.
Could you give us more details about that (e.g. is the list always empty, or only in certain situations?) and possibly add some logging to your code?
-
Also, getSelectedDocuments() returns an empty list, even though multiple documents are checked on the document table. Why would that be?
0 -
Thank you Jonas!
When I call getSelectedDocuments, I'm doing it from a service.
I go to the document table, select 2 plasmids with the blue checkboxes, then go to my service and click the button in the panel (it's a GeneiousServiceWithPanel) to start execution, but DocumentUtilities.getSelectedUtilities() is empty. This is the only context is which I use this method in my plugin, and I've confirmed that the list of returned documents is in fact empty using a console print statement.
0 -
In the second reference there, I meant to say getSelectedDocuments again, not getSelectedUtilities, sorry for the typo.
0 -
It sounds like the problem is that you're unselected the documents by selecting your new service.
You might be better off implementing this as a DocumentOperation https://assets.geneious.com/developer/geneious/javadoc/latest/com/biomatters/geneious/publicapi/plugin/DocumentOperation.html. That'll let you add a button into the UI (menu or toolbar etc) that runs your code.
0
Please sign in to leave a comment.
Comments
5 comments