@Override
 public QueryFuture<FeatureSet> getQuery(FeatureSet set, int queryNum) {
   if (queryNum == 0) {
     /// limits us to CHROM #21
     return SWQEFactory.getQueryInterface()
         .getFeaturesByAttributes(
             0,
             set,
             new RPNStack(
                 new RPNStack.FeatureAttribute("seqid"),
                 new RPNStack.Constant("21"),
                 RPNStack.Operation.EQUAL));
   } else if (queryNum == 1) {
     // limits us to the range of 20000000 through 30000000
     return SWQEFactory.getQueryInterface()
         .getFeaturesByRange(0, set, QueryInterface.Location.INCLUDES, "21", 20000000, 30000000);
   } else {
     // limits us to features with a particular tag
     return SWQEFactory.getQueryInterface()
         .getFeaturesByAttributes(
             0,
             set,
             new RPNStack(
                 new RPNStack.TagOccurrence(
                     QueryVCFDumperTest.AD_HOC_TAG_SET, "non_synonymous_codon")));
   }
 }
Beispiel #2
0
  /** export. */
  public void export() {

    if (args.length < 1 || args.length > 2) {
      System.err.println(args.length + " arguments found");
      System.out.println("VCFDumper <featureSetID> [outputFile]");
      System.exit(-1);
    }

    // parse a SGID from a String representation, we need a more elegant solution here
    String featureSetID = args[0];
    SGID sgid = Utility.parseSGID(featureSetID);
    FeatureSet fSet = SWQEFactory.getQueryInterface().getLatestAtomBySGID(sgid, FeatureSet.class);

    // if this featureSet does not exist
    if (fSet == null) {
      System.out.println("featureSet ID not found");
      System.exit(-2);
    }
    dumpVCFFromFeatureSetID(fSet, (args.length == 2 ? args[1] : null));
  }
Beispiel #3
0
  /**
   * dumpVCFFromFeatureSetID.
   *
   * @param fSet a {@link com.github.seqware.queryengine.model.FeatureSet} object.
   * @param file a {@link java.lang.String} object.
   */
  public static void dumpVCFFromFeatureSetID(FeatureSet fSet, String file) {
    BufferedWriter outputStream = null;

    try {
      if (file != null) {
        outputStream = new BufferedWriter(new FileWriter(file));
      } else {
        outputStream = new BufferedWriter(new OutputStreamWriter(System.out));
      }
      outputStream.append("#CHROM	POS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n");
    } catch (IOException e) {
      Logger.getLogger(VCFDumper.class.getName())
          .fatal("Exception thrown starting export to file:", e);
      System.exit(-1);
    }

    boolean caughtNonVCF = false;
    boolean mrSuccess = false;
    if (SWQEFactory.getQueryInterface() instanceof MRHBasePersistentBackEnd) {
      // hack to use VCF MR
      if (SWQEFactory.getModelManager() instanceof MRHBaseModelManager) {
        try {
          // pretend that the included
          // com.github.seqware.queryengine.plugins.hbasemr.MRFeaturesByAttributesPlugin is an
          // external plug-in
          Class<? extends PluginInterface> arbitraryPlugin;
          arbitraryPlugin = VCFDumperPlugin.class;
          // get a FeatureSet from the back-end
          QueryFuture<File> future =
              SWQEFactory.getQueryInterface().getFeaturesByPlugin(0, arbitraryPlugin, fSet);
          File get = future.get();
          BufferedReader in = new BufferedReader(new FileReader(get));
          IOUtils.copy(in, outputStream);
          in.close();
          get.deleteOnExit();
          outputStream.flush();
          outputStream.close();
          mrSuccess = true;
        } catch (IOException e) {
          // fail out on IO error
          Logger.getLogger(VCFDumper.class.getName())
              .fatal("Exception thrown exporting to file:", e);
          System.exit(-1);
        } catch (Exception e) {
          Logger.getLogger(VCFDumper.class.getName())
              .info("MapReduce exporting failed, falling-through to normal exporting to file");
          // fall-through and do normal exporting if Map Reduce exporting fails
        }
      } // TODO: clearly this should be expanded to include closing database etc
    }
    if (mrSuccess) {
      return;
    }
    // fall-through if plugin-fails
    try {
      for (Feature feature : fSet) {
        StringBuffer buffer = new StringBuffer();
        boolean caught = outputFeatureInVCF(buffer, feature);
        if (caught) {
          caughtNonVCF = true;
        }
        outputStream.append(buffer);
        outputStream.newLine();
      }
      outputStream.flush();
    } catch (IOException e) {
      Logger.getLogger(VCFDumper.class.getName()).fatal("Exception thrown exporting to file:", e);
      System.exit(-1);
    } finally {
      IOUtils.closeQuietly(outputStream);
    }
  }