0
头像

如何通过 Geneious API 以编程方式导入树

除非您正在为 Geneious 不支持的树文件格式编写自己的导入器,否则有两种不同的通用方法可以将树导入 Geneious,具体取决于您是否在自动检测文件格式时遇到问题。

PluginUtilities.importDocuments() 应该以Geneious可以读取的任何格式导入树文件。例如:

私人名单<AnnotatedPluginDocument>getTreesFromFile( String filename, ProgressListener progress)抛出DocumentImportException, IOException { File treeFile = new File(filename); if (!treeFile.exists()) { throw new DocumentImportException( "树文件" +文件名+ "不存在" ); } 列表<AnnotatedPluginDocument>文档 = PluginUtilities.importDocuments(treeFile, progress); for (AnnotatedPluginDocument doc : 文档) { if (! 树文档。班级。 isAssignableFrom(doc.getDocumentClass())) { throw new DocumentImportException( "文档不是树:" + doc.getName()); } }返回文件; }

这将返回一个(单例)列表,其中包含输入文件中的树,前提是它存在并包含一个或多个树。

这可能是您应该使用的方法,除非您的文件存在一些难以检测格式的问题。另一种方法,如果你想指定你想导入的树的格式,是使用作为我们公共 API 一部分的 JEBL 类。JEBL 的文档可在 Sourceforge 上找到,这是指向 jebl.evolution.io 包,其中包括进口商:http://jebl.sourceforge.net/doc/api/jebl/evolution/io/package-summary.html

例如,我从 devkit 复制并修改了 ExampleFastaImporter 模块以创建一个使用 jebl.evolution.io.NewickImporter 做这项工作:

com.biomatters.exampleTreeImporterPlugin;导入com.biomatters.geneious.publicapi.implementations.DefaultSameTaxaTreesDocument;导入com.biomatters.geneious.publicapi.plugin.DocumentFileImporter;导入com.biomatters.geneious.publicapi.plugin.DocumentImportException;导入com.biomatters.geneious.publicapi.utilities.ProgressInputStream;导入jebl.evolution.io.ImportException;导入jebl.evolution.io.NewickImporter;导入jebl.evolution.trees.Tree;导入jebl.util.ProgressListener;导入java.io.BufferedReader;导入java.io.File;导入java.io.IOException;导入java.io.InputStreamReader;导入java.util.Date;导入java.util.List; public class ExampleTreeImporter extends DocumentFileImporter { public String [] getPermissibleExtensions() { return new String []{ ".tree" , ".tre" }; } public String getFileTypeDescription() { return "Example Tree Importer" ; } public AutoDetectStatustentativeAutoDetect(File file, String fileContentsStart) { if (fileContentsStart.startsWith( "(" )) { return AutoDetectStatus.MAYBE; } else { return AutoDetectStatus.REJECT_FILE; } } public void importDocuments(File file, ImportCallback callback, ProgressListener progressListener)抛出IOException, DocumentImportException { BufferedReader reader = new BufferedReader( new InputStreamReader( new ProgressInputStream(progressListener, file))); NewickImporter importer = new NewickImporter(reader, true ); List<Tree>树木;尝试{ 树 = importer.importTrees(); } catch (ImportException e) { throw new DocumentImportException(e.getMessage()); } callback.addDocument( new DefaultSameTaxaTreesDocument(trees, file.getName(), new Date())); } }

如果您正在为新文件格式编写自己的导入器,则需要查看 JEBL 文档(jebl.evolution.trees 包裹)。您可能需要创建一个 DefaultSameTaxaTreesDocument 或 默认系统发育文件 取决于您是否附加对齐方式,但无论哪种方式,您都需要查看 JEBL 提供的树数据结构。

希拉里·米勒(Hilary Miller)