Ejemplo n.º 1
0
  @Exec
  public void exec() throws IOException, CommandArgumentException {
    if (filename == null) {
      throw new CommandArgumentException("You must specify an input BAM filename!");
    }
    SamReaderFactory readerFactory = SamReaderFactory.makeDefault();
    if (lenient) {
      readerFactory.validationStringency(ValidationStringency.LENIENT);
    } else if (silent) {
      readerFactory.validationStringency(ValidationStringency.SILENT);
    }

    SamReader reader = null;
    String name;
    FileChannel channel = null;
    if (filename.equals("-")) {
      reader = readerFactory.open(SamInputResource.of(System.in));
      name = "<stdin>";
    } else {
      File f = new File(filename);
      FileInputStream fis = new FileInputStream(f);
      channel = fis.getChannel();
      reader = readerFactory.open(SamInputResource.of(fis));
      name = f.getName();
    }

    Iterator<SAMRecord> it =
        ProgressUtils.getIterator(
            name,
            reader.iterator(),
            (channel == null) ? null : new FileChannelStats(channel),
            new ProgressMessage<SAMRecord>() {
              long i = 0;

              @Override
              public String msg(SAMRecord current) {
                i++;
                return i + " " + current.getReadName();
              }
            },
            new CloseableFinalizer<SAMRecord>());
    long i = 0;
    while (it.hasNext()) {
      i++;
      it.next();
    }
    reader.close();
    System.err.println("Successfully read: " + i + " records.");
  }
Ejemplo n.º 2
0
 public void close() throws IOException {
   if (reader != null) {
     reader.close();
   }
 }