@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;
  }
  @Override
  public List<AnnotatedPluginDocument> performOperation(
      AnnotatedPluginDocument[] annotatedDocuments,
      ProgressListener progressListener,
      Options options)
      throws DocumentOperationException {
    int PAGE_SIZE = 2;
    try {
      String query = options.getValueAsString("query");
      int count = 0;
      InputStream countInput = queryServer("query count " + query);
      // Get the response
      BufferedReader rd = new BufferedReader(new InputStreamReader(countInput));
      String line;
      while ((line = rd.readLine()) != null) {
        count = Integer.parseInt(line.trim());
      }
      rd.close();

      int numberOfPages = (int) Math.ceil(count / PAGE_SIZE);

      CompositeProgressListener composite =
          new CompositeProgressListener(progressListener, numberOfPages);

      for (int page = 0; page < numberOfPages; page++) {
        InputStream inputStream =
            queryServer("query page_size " + PAGE_SIZE + " page_number " + page + " text " + query);
        File outputFile =
            new File(
                System.getProperty("user.home")
                    + File.separator
                    + "traceData"
                    + File.separator
                    + "part"
                    + page
                    + ".tgz");
        BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile));
        List<String> ids = new ArrayList<String>();
        String line2 = null;
        while ((line2 = in.readLine()) != null) {
          if (composite.isCanceled()) {
            break;
          }
          System.out.println(line2);
          // out.write(n);
          ids.add(line2);
        }
        if (composite.isCanceled()) {
          break;
        }
        in.close();
        InputStream tgzIn = queryServer("retrieve_gz all " + StringUtilities.join(", ", ids));
        int n;
        int byteCount = 0;
        while ((n = tgzIn.read()) >= 0) {
          byteCount++;
          composite.setMessage("Downloaded " + byteCount + " bytes");
          if (composite.isCanceled()) {
            break;
          }
          // out.write(n);
        }
        tgzIn.close();
        out.close();
        if (composite.isCanceled()) {
          break;
        }
        composite.beginNextSubtask();
        break;
        // out.close();
      }

    } catch (IOException ex) {
      ex.toString();
      ex.printStackTrace();
      throw new DocumentOperationException(ex.getMessage(), ex);
    }
    return Collections.emptyList();
  }