Ejemplo n.º 1
0
 /**
  * Finds the adaptor boundary around the read and returns the first base inside the adaptor that
  * is closest to the read boundary. If the read is in the positive strand, this is the first base
  * after the end of the fragment (Picard calls it 'insert'), if the read is in the negative
  * strand, this is the first base before the beginning of the fragment.
  *
  * <p>There are two cases we need to treat here:
  *
  * <p>1) Our read is in the reverse strand :
  *
  * <p><----------------------| * |--------------------->
  *
  * <p>in these cases, the adaptor boundary is at the mate start (minus one)
  *
  * <p>2) Our read is in the forward strand :
  *
  * <p>|----------------------> * <----------------------|
  *
  * <p>in these cases the adaptor boundary is at the start of the read plus the inferred insert
  * size (plus one)
  *
  * @param read the read being tested for the adaptor boundary
  * @return the reference coordinate for the adaptor boundary (effectively the first base IN the
  *     adaptor, closest to the read. CANNOT_COMPUTE_ADAPTOR_BOUNDARY if the read is unmapped or
  *     the mate is mapped to another contig.
  */
 public static int getAdaptorBoundary(final GATKRead read) {
   if (!hasWellDefinedFragmentSize(read)) {
     return CANNOT_COMPUTE_ADAPTOR_BOUNDARY;
   } else if (read.isReverseStrand()) {
     return read.getMateStart() - 1; // case 1 (see header)
   } else {
     final int insertSize =
         Math.abs(
             read
                 .getFragmentLength()); // the inferred insert size can be negative if the mate is
                                        // mapped before the read (so we take the absolute value)
     return read.getStart() + insertSize + 1; // case 2 (see header)
   }
 }
Ejemplo n.º 2
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();
    }
  }
Ejemplo 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;
  }
Ejemplo n.º 4
0
 /**
  * Returns the read's unclipped start if the read is on the forward strand, or the read's
  * unclipped end if the read is on the reverse strand.
  *
  * @param read read whose stranded unclipped start to retrieve
  * @return the read's unclipped start if the read is on the forward strand, or the read's
  *     unclipped end if the read is on the reverse strand.
  */
 public static int getStrandedUnclippedStart(final GATKRead read) {
   return read.isReverseStrand() ? read.getUnclippedEnd() : read.getUnclippedStart();
 }