Esempio n. 1
0
 /**
  * Check to ensure that the alignment makes sense based on the contents of the header.
  *
  * @param header The SAM file header.
  * @param read The read to verify.
  * @return true if alignment agrees with header, false otherwise.
  */
 public static boolean alignmentAgreesWithHeader(final SAMFileHeader header, final GATKRead read) {
   final int referenceIndex = getReferenceIndex(read, header);
   // Read is aligned to nonexistent contig
   if (!read.isUnmapped() && referenceIndex == SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX) {
     return false;
   }
   final SAMSequenceRecord contigHeader = header.getSequence(referenceIndex);
   // Read is aligned to a point after the end of the contig
   return read.isUnmapped() || read.getStart() <= contigHeader.getSequenceLength();
 }
Esempio n. 2
0
  /**
   * Returns the reference index in the given header of the read's contig, or {@link
   * SAMRecord#NO_ALIGNMENT_REFERENCE_INDEX} if the read is unmapped.
   *
   * @param read read whose reference index to look up
   * @param header SAM header defining contig indices
   * @return the reference index in the given header of the read's contig, or {@link
   *     SAMRecord#NO_ALIGNMENT_REFERENCE_INDEX} if the read is unmapped.
   */
  public static int getReferenceIndex(final GATKRead read, final SAMFileHeader header) {
    if (read.isUnmapped()) {
      return SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX;
    }

    return header.getSequenceIndex(read.getContig());
  }
Esempio n. 3
0
  /**
   * Construct a set of SAM bitwise flags from a GATKRead
   *
   * @param read read from which to construct the flags
   * @return SAM-compliant set of bitwise flags reflecting the properties in the given read
   */
  public static int getSAMFlagsForRead(final GATKRead read) {
    int samFlags = 0;

    if (read.isPaired()) {
      samFlags |= SAM_READ_PAIRED_FLAG;
    }
    if (read.isProperlyPaired()) {
      samFlags |= SAM_PROPER_PAIR_FLAG;
    }
    if (read.isUnmapped()) {
      samFlags |= SAM_READ_UNMAPPED_FLAG;
    }
    if (read.isPaired() && read.mateIsUnmapped()) {
      samFlags |= SAM_MATE_UNMAPPED_FLAG;
    }
    if (!read.isUnmapped() && read.isReverseStrand()) {
      samFlags |= SAM_READ_STRAND_FLAG;
    }
    if (read.isPaired() && !read.mateIsUnmapped() && read.mateIsReverseStrand()) {
      samFlags |= SAM_MATE_STRAND_FLAG;
    }
    if (read.isFirstOfPair()) {
      samFlags |= SAM_FIRST_OF_PAIR_FLAG;
    }
    if (read.isSecondOfPair()) {
      samFlags |= SAM_SECOND_OF_PAIR_FLAG;
    }
    if (read.isSecondaryAlignment()) {
      samFlags |= SAM_NOT_PRIMARY_ALIGNMENT_FLAG;
    }
    if (read.failsVendorQualityCheck()) {
      samFlags |= SAM_READ_FAILS_VENDOR_QUALITY_CHECK_FLAG;
    }
    if (read.isDuplicate()) {
      samFlags |= SAM_DUPLICATE_READ_FLAG;
    }
    if (read.isSupplementaryAlignment()) {
      samFlags |= SAM_SUPPLEMENTARY_ALIGNMENT_FLAG;
    }

    return samFlags;
  }
Esempio n. 4
0
  /**
   * Can the adaptor sequence of read be reliably removed from the read based on the alignment of
   * read and its mate?
   *
   * @param read the read to check
   * @return true if it can, false otherwise
   */
  public static boolean hasWellDefinedFragmentSize(final GATKRead read) {
    if (read.getFragmentLength() == 0)
    // no adaptors in reads with mates in another chromosome or unmapped pairs
    {
      return false;
    }
    if (!read.isPaired())
    // only reads that are paired can be adaptor trimmed
    {
      return false;
    }
    if (read.isUnmapped() || read.mateIsUnmapped())
    // only reads when both reads are mapped can be trimmed
    {
      return false;
    }
    //        if ( ! read.isProperlyPaired() )
    //            // note this flag isn't always set properly in BAMs, can will stop us from
    // eliminating some proper pairs
    //            // reads that aren't part of a proper pair (i.e., have strange alignments) can't
    // be trimmed
    //            return false;
    if (read.isReverseStrand() == read.mateIsReverseStrand())
    // sanity check on isProperlyPaired to ensure that read1 and read2 aren't on the same strand
    {
      return false;
    }

    if (read.isReverseStrand()) {
      // we're on the negative strand, so our read runs right to left
      return read.getEnd() > read.getMateStart();
    } else {
      // we're on the positive strand, so our mate should be to our right (his start + insert size
      // should be past our start)
      return read.getStart() <= read.getMateStart() + read.getFragmentLength();
    }
  }
Esempio n. 5
0
 public static boolean isNonPrimary(GATKRead read) {
   return read.isSecondaryAlignment() || read.isSupplementaryAlignment() || read.isUnmapped();
 }