Ejemplo n.º 1
0
 @Override
 public void close() {
   try {
     in.close();
   } catch (final IOException e) {
     throw new RuntimeIOException(e);
   }
 }
Ejemplo n.º 2
0
  public static void main(String[] args) throws IOException {
    final GenericOptionsParser parser;
    try {
      parser = new GenericOptionsParser(args);

      // This should be IOException but Hadoop 0.20.2 doesn't throw it...
    } catch (Exception e) {
      System.err.printf("Error in Hadoop arguments: %s\n", e.getMessage());
      System.exit(1);

      // Hooray for javac
      return;
    }

    args = parser.getRemainingArgs();
    // final Configuration conf = ContextUtil.getConfiguration(parser);
    final Configuration conf = parser.getConfiguration();

    long beg = 0;

    if (args.length < 2 || args.length > 3) {
      System.err.println("Usage: BAMSplitGuesser path-or-uri header-path-or-uri [beg]");
      System.exit(2);
    }

    try {
      if (args.length > 2) beg = Long.decode(args[2]);
    } catch (NumberFormatException e) {
      System.err.println("Invalid beg offset.");
      if (e.getMessage() != null) System.err.println(e.getMessage());
      System.exit(2);
    }

    SeekableStream ss = WrapSeekable.openPath(conf, new Path(args[0]));
    SeekableStream hs = WrapSeekable.openPath(conf, new Path(args[1]));

    final long end = beg + MAX_BYTES_READ;

    System.out.printf(
        "Will look for a BGZF block within: [%1$#x,%2$#x) = [%1$d,%2$d)\n"
            + "Will then verify BAM data within:  [%1$#x,%3$#x) = [%1$d,%3$d)\n",
        beg, beg + 0xffff, end);

    final long g = new BAMSplitGuesser(ss, hs, conf).guessNextBAMRecordStart(beg, end);

    ss.close();

    if (g == end) {
      System.out.println("Didn't find any acceptable BAM record in any BGZF block.");
      System.exit(1);
    }

    System.out.printf(
        "Accepted BGZF block at offset %1$#x (%1$d).\n"
            + "Accepted BAM record at offset %2$#x (%2$d) therein.\n",
        g >> 16, g & 0xffff);
  }