コード例 #1
0
 @Override
 protected void map(
     LongWritable ignored,
     SAMRecordWritable wrec,
     Mapper<LongWritable, SAMRecordWritable, Text, SAMRecordWritable>.Context ctx)
     throws InterruptedException, IOException {
   Utils.correctSAMRecordForMerging(wrec.get(), ContextUtil.getConfiguration(ctx));
   ctx.write(new Text(wrec.get().getReadName()), wrec);
 }
コード例 #2
0
  @Override
  protected void reduce(
      Text key,
      Iterable<SAMRecordWritable> records,
      Reducer<Text, SAMRecordWritable, Text, SAMRecordWritable>.Context ctx)
      throws IOException, InterruptedException {
    // Non-primary records are simply written out, but as long as we can find
    // two primaries, pair them up.

    final SAMFileHeader header =
        Utils.getSAMHeaderMerger(ContextUtil.getConfiguration(ctx)).getMergedHeader();

    final Iterator<SAMRecordWritable> it = records.iterator();

    while (it.hasNext()) {
      SAMRecordWritable a = it.next();

      if (a.get().getNotPrimaryAlignmentFlag()) {
        ctx.write(key, a);
        continue;
      }

      // Cache the record since the iterator does its own caching, meaning
      // that after another it.next() we would have a == b.
      wrec.set(a.get());
      a = wrec;

      SAMRecordWritable b = null;
      while (it.hasNext()) {
        b = it.next();
        if (!b.get().getNotPrimaryAlignmentFlag()) break;
        ctx.write(key, b);
      }

      if (b == null) {
        // No more primaries, so just write the unpaired one as-is.
        ctx.write(key, a);
        break;
      }

      a.get().setHeader(header);
      b.get().setHeader(header);
      SamPairUtil.setMateInfo(a.get(), b.get(), header);

      ctx.write(key, a);
      ctx.write(key, b);
    }
  }