/**
  * Copy the content in the directory with the given name located in the <code>test_data</code>
  * directory in the plug-in with the given id into the specified target directory.
  *
  * @param pluginId the id of the plug-in containing the project
  * @param projectName the name of the directory containing the project
  * @param targetDirectory the directory into which the content is copied. This directory is
  *     created if it does not already exist
  * @throws IOException if a required file cannot be accessed
  */
 public static void copyPluginRelativeContent(
     String pluginId, String projectName, File targetDirectory) throws IOException {
   URL pluginInstallUri = PluginUtilities.getInstallUrl(pluginId);
   URL sourceUrl = new URL(pluginInstallUri, PROJECT_DIRECTORY_NAME + "/" + projectName);
   IPath sourcePath = new Path(FileLocator.toFileURL(sourceUrl).getPath());
   FileUtilities.copyDirectoryContents(sourcePath.toFile(), targetDirectory);
 }
Example #2
0
 public static String getParameterValue(IExtension ext, String key, String defaultValue) {
   String val = PluginUtilities.getAttribute(ext, key);
   if (val == null) {
     return defaultValue;
   }
   if (isProtegeProperty(val)) {
     return getProtegeProperty(val);
   } else {
     return val;
   }
 }
 /**
  * Return the absolute path to the resource within the specified plug-in with the given relative
  * path.
  *
  * @param pluginId the id of the plug-in containing the resource
  * @param relativePath the relative path of the resource within the project
  * @return the absolute path to the resource
  * @throws IOException if some portion of the path is invalid
  */
 public static IPath getPluginRelativePath(String pluginId, IPath relativePath)
     throws IOException {
   IPath pluginPath =
       new Path(FileLocator.toFileURL(PluginUtilities.getInstallUrl(pluginId)).getPath());
   return pluginPath.append(relativePath);
 }
  @Override
  public List<AnnotatedPluginDocument> performOperation(
      AnnotatedPluginDocument[] annotatedDocuments,
      ProgressListener progressListener,
      Options options)
      throws DocumentOperationException {
    String queryText = ((ExampleWorkflowOptions) options).getSearchQuery();
    // First create a composite progress to represent the 3 components of this example
    // 1) Getting the results from NCBI (80% of total time)
    // 2) Building the alignment (15% of total time)
    // 3) Building a tree (5% of total time)
    CompositeProgressListener compositeProgress =
        new CompositeProgressListener(progressListener, 0.8, 0.15, 0.05);

    // First get the ncbi database and search it:
    compositeProgress.beginSubtask("Searching NCBI");
    DatabaseService ncbiNucleotideService =
        (DatabaseService) PluginUtilities.getGeneiousService("NCBI_nucleotide_gbc");
    // The various services available are found by running this commented out code:
    // for (GeneiousService service : PluginUtilities.getGeneiousServices()) {
    //    System.out.println(service.getUniqueID());
    // }
    Query query = Query.Factory.createQuery(queryText);
    List<AnnotatedPluginDocument> sequences;
    try {
      sequences = ncbiNucleotideService.retrieve(query, compositeProgress);
    } catch (DatabaseServiceException e) {
      throw new DocumentOperationException("Failed to search NCBI database", e);
    }
    if (compositeProgress.isCanceled()) throw new DocumentOperationException.Canceled();
    if (sequences.size() < 3)
      throw new DocumentOperationException(
          "NCBI returned "
              + sequences.size()
              + " results, but we require at least 3 to build a tree");

    // Now get the alignment operation and perform the alignment:
    compositeProgress.beginSubtask("Build alignment");
    final DocumentOperation alignmentOperation =
        PluginUtilities.getCategoryOperation(GeneiousActionOptions.Category.Alignment);
    Options alignmentOptions =
        alignmentOperation.getOptions(
            sequences); // Get the options provided by the alignment operation.
    alignmentOptions.setValue(
        "operation", "MUSCLE_NUCLEOTIDE_"); // Tell it to use muscle for alignment.
    // To find out what options are available on the alignment do the following commented out line:
    // System.out.println(alignmentOptions.getDescriptionAndState());

    List<AnnotatedPluginDocument> alignment =
        alignmentOperation.performOperation(sequences, compositeProgress, alignmentOptions);
    if (compositeProgress.isCanceled()) throw new DocumentOperationException.Canceled();

    // Now get the tree operation and build a tree:
    compositeProgress.beginSubtask("Build tree");
    final DocumentOperation treeOperation =
        PluginUtilities.getCategoryOperation(GeneiousActionOptions.Category.TreeBuilding);
    Options treeOptions = treeOperation.getOptions(alignment);
    treeOptions.setValue("treeBuilding.buildMethod", "UPGMA");
    // To find out what options are available on the tree builder, do the following commented out
    // line:
    // System.out.println(treeOptions.getDescriptionAndState());

    final List<AnnotatedPluginDocument> treeResults =
        treeOperation.performOperation(alignment, compositeProgress, treeOptions);
    if (treeResults != null && treeResults.size() == 1) {
      treeResults.get(0).setName("Tree of " + queryText);
    }
    return treeResults;
  }