/**
   * Returns the mate for a paired-end read. Please note that this method will return an unmapped
   * mate for any single end read as well. Do check if the read is paired before calling getMate().
   *
   * @return The mate, or a constant unmapped mate (for single end reads, or paired end where the
   *     mate is not found).
   */
  public ReadMate getMate() {
    if (entry.hasPairAlignmentLink()) {
      Alignments.RelatedAlignmentEntry link = entry.getPairAlignmentLink();
      String mateChr = getChromosome(link.getTargetIndex());
      int mateStart = link.getPosition();
      boolean mateNegativeStrand = EntryFlagHelper.isMateReverseStrand(entry);

      boolean isReadUnmappedFlag = EntryFlagHelper.isReadUnmapped(entry);
      final ReadMate mate =
          new ReadMate(mateChr, mateStart, mateNegativeStrand, isReadUnmappedFlag);
      return mate;
    } else {
      return unmappedMate;
    }
  }
  /**
   * Verify that the list has an appropriate unbroken chain of back links.
   *
   * @param list the list of splices to validate
   * @return true if the list has an unbroken chain of back links
   */
  boolean spliceListIsValid(final ObjectArrayList<GobyAlignment> list) {

    if (list != null && list.size() > 1) {
      Alignments.AlignmentEntry prevEntry = list.get(0).entry;
      for (int i = 1; i < list.size(); i++) {
        Alignments.AlignmentEntry currentEntry = list.get(i).entry;
        if (!currentEntry.hasSplicedBackwardAlignmentLink()) return false;
        else {
          Alignments.RelatedAlignmentEntry currentBackwardLink =
              currentEntry.getSplicedBackwardAlignmentLink();

          if ((prevEntry.getQueryIndex() != currentEntry.getQueryIndex())
              || (prevEntry.getFragmentIndex() != currentBackwardLink.getFragmentIndex())
              || (prevEntry.getPosition() != currentBackwardLink.getPosition())
              || (prevEntry.getTargetIndex() != currentBackwardLink.getTargetIndex())) {
            return false;
          }
        }
        prevEntry = currentEntry;
      }
    }
    return true;
  }