Esempio n. 1
0
 /**
  * Shallow copy of everything, except for the attribute list and the temporary attributes. A new
  * list of the attributes is created for both, but the attributes themselves are copied by
  * reference. This should be safe because callers should never modify a mutable value returned by
  * any of the get() methods anyway.
  *
  * @return a shallow copy of the GATKSAMRecord
  */
 @Override
 public Object clone() {
   try {
     final GATKSAMRecord clone = (GATKSAMRecord) super.clone();
     if (temporaryAttributes != null) {
       clone.temporaryAttributes = new HashMap<>();
       for (Object attribute : temporaryAttributes.keySet())
         clone.setTemporaryAttribute(attribute, temporaryAttributes.get(attribute));
     }
     return clone;
   } catch (final CloneNotSupportedException e) {
     throw new RuntimeException(e);
   }
 }
Esempio n. 2
0
  /**
   * Creates a new GATKSAMRecord with the source read's header, read group and mate information, but
   * with the following fields set to user-supplied values: - Read Bases - Base Qualities - Base
   * Insertion Qualities - Base Deletion Qualities
   *
   * <p>Cigar string is empty (not-null)
   *
   * <p>Use this method if you want to create a new GATKSAMRecord based on another GATKSAMRecord,
   * but with modified bases and qualities
   *
   * @param read a read to copy the header from
   * @param readBases an array containing the new bases you wish use in place of the originals
   * @param baseQualities an array containing the new base qualities you wish use in place of the
   *     originals
   * @param baseInsertionQualities an array containing the new base insertion qaulities
   * @param baseDeletionQualities an array containing the new base deletion qualities
   * @return a read with modified bases and qualities, safe for the GATK
   */
  public static GATKSAMRecord createQualityModifiedRead(
      final GATKSAMRecord read,
      final byte[] readBases,
      final byte[] baseQualities,
      final byte[] baseInsertionQualities,
      final byte[] baseDeletionQualities) {
    if (baseQualities.length != readBases.length
        || baseInsertionQualities.length != readBases.length
        || baseDeletionQualities.length != readBases.length)
      throw new IllegalArgumentException(
          "Read bases and read quality arrays aren't the same size: Bases:"
              + readBases.length
              + " vs Base Q's:"
              + baseQualities.length
              + " vs Insert Q's:"
              + baseInsertionQualities.length
              + " vs Delete Q's:"
              + baseDeletionQualities.length);

    final GATKSAMRecord processedRead = GATKSAMRecord.emptyRead(read);
    processedRead.setReadBases(readBases);
    processedRead.setBaseQualities(baseQualities, EventType.BASE_SUBSTITUTION);
    processedRead.setBaseQualities(baseInsertionQualities, EventType.BASE_INSERTION);
    processedRead.setBaseQualities(baseDeletionQualities, EventType.BASE_DELETION);

    return processedRead;
  }
Esempio n. 3
0
  /**
   * Creates an empty GATKSAMRecord with the read's header, read group and mate information, but
   * empty (not-null) fields: - Cigar String - Read Bases - Base Qualities
   *
   * <p>Use this method if you want to create a new empty GATKSAMRecord based on another
   * GATKSAMRecord
   *
   * @param read a read to copy the header from
   * @return a read with no bases but safe for the GATK
   */
  public static GATKSAMRecord emptyRead(GATKSAMRecord read) {
    final GATKSAMRecord emptyRead = new GATKSAMRecord(read.getHeader());
    emptyRead.setReferenceIndex(read.getReferenceIndex());
    emptyRead.setAlignmentStart(0);
    emptyRead.setMappingQuality(0);
    // setting read indexing bin last
    emptyRead.setFlags(read.getFlags());
    emptyRead.setMateReferenceIndex(read.getMateReferenceIndex());
    emptyRead.setMateAlignmentStart(read.getMateAlignmentStart());
    emptyRead.setInferredInsertSize(read.getInferredInsertSize());

    emptyRead.setCigarString("");
    emptyRead.setReadBases(new byte[0]);
    emptyRead.setBaseQualities(new byte[0]);

    SAMReadGroupRecord samRG = read.getReadGroup();
    emptyRead.clearAttributes();
    if (samRG != null) {
      GATKSAMReadGroupRecord rg = new GATKSAMReadGroupRecord(samRG);
      emptyRead.setReadGroup(rg);
    }

    GATKBin.setReadIndexingBin(emptyRead, 0);

    return emptyRead;
  }