Beispiel #1
0
  /**
   * checks if the read has a platform tag in the readgroup equal to 'name'. Assumes that 'name' is
   * upper-cased.
   *
   * @param read the read to test
   * @param name the upper-cased platform name to test
   * @return whether or not name == PL tag in the read group of read
   */
  public static boolean isPlatformRead(SAMRecord read, String name) {

    SAMReadGroupRecord readGroup = read.getReadGroup();
    if (readGroup != null) {
      Object readPlatformAttr = readGroup.getAttribute("PL");
      if (readPlatformAttr != null) return readPlatformAttr.toString().toUpperCase().contains(name);
    }
    return false;
  }
  protected ReadDestination(final SAMFileHeader header, final String readGroupID) {
    // prepare the bam header
    if (header == null) throw new IllegalArgumentException("header cannot be null");
    bamHeader = new SAMFileHeader();
    bamHeader.setSequenceDictionary(header.getSequenceDictionary());
    bamHeader.setSortOrder(SAMFileHeader.SortOrder.coordinate);

    // include the original read groups plus a new artificial one for the haplotypes
    final List<SAMReadGroupRecord> readGroups =
        new ArrayList<SAMReadGroupRecord>(header.getReadGroups());
    final SAMReadGroupRecord rg = new SAMReadGroupRecord(readGroupID);
    rg.setSample("HC");
    rg.setSequencingCenter("BI");
    readGroups.add(rg);
    bamHeader.setReadGroups(readGroups);
  }
Beispiel #3
0
 public boolean filterOut(final SAMRecord read) {
   final SAMReadGroupRecord readGroup = read.getReadGroup();
   return !(readGroup != null && readGroup.getReadGroupId().equals(READ_GROUP_TO_KEEP));
 }
  protected int doWork() {
    IoUtil.assertFileIsReadable(INPUT);
    IoUtil.assertFileIsWritable(OUTPUT);

    final SAMFileReader in = new SAMFileReader(INPUT);

    // create the read group we'll be using
    final SAMReadGroupRecord rg = new SAMReadGroupRecord(RGID);
    rg.setLibrary(RGLB);
    rg.setPlatform(RGPL);
    rg.setSample(RGSM);
    rg.setPlatformUnit(RGPU);
    if (RGCN != null) rg.setSequencingCenter(RGCN);
    if (RGDS != null) rg.setDescription(RGDS);
    if (RGDT != null) rg.setRunDate(RGDT);

    log.info(
        String.format(
            "Created read group ID=%s PL=%s LB=%s SM=%s%n",
            rg.getId(), rg.getPlatform(), rg.getLibrary(), rg.getSample()));

    // create the new header and output file
    final SAMFileHeader inHeader = in.getFileHeader();
    final SAMFileHeader outHeader = inHeader.clone();
    outHeader.setReadGroups(Arrays.asList(rg));
    if (SORT_ORDER != null) outHeader.setSortOrder(SORT_ORDER);

    final SAMFileWriter outWriter =
        new SAMFileWriterFactory()
            .makeSAMOrBAMWriter(
                outHeader, outHeader.getSortOrder() == inHeader.getSortOrder(), OUTPUT);

    final ProgressLogger progress = new ProgressLogger(log);
    for (final SAMRecord read : in) {
      read.setAttribute(SAMTag.RG.name(), RGID);
      outWriter.addAlignment(read);
      progress.record(read);
    }

    // cleanup
    in.close();
    outWriter.close();
    return 0;
  }