Examples of CigarElement


Examples of net.sf.samtools.CigarElement

 
  private void processLocus(ReadsAtLocus normalReads, ReadsAtLocus tumorReads) {
    String chromosome = normalReads.getChromosome();
    int position = normalReads.getPosition();
   
    CigarElement tumorIndel = null;
    int tumorCount = 0;
    int tumorRefCount = 0;
    int mismatch0Count = 0;
    int mismatch1Count = 0;
    int totalMismatchCount = 0;
    boolean hasSufficientDistanceFromReadEnd = false;
    int maxContigMapq = 0;
    int minReadIndex = Integer.MAX_VALUE;
    int maxReadIndex = Integer.MIN_VALUE;
    int normalCount = 0;
    int normalRefCount = 0;
   
    Map<String, Integer> insertBasesMap = new HashMap<String, Integer>();
   
    for (SAMRecord read : tumorReads.getReads()) {
      if (!read.getDuplicateReadFlag()) {
     
        IndelInfo readElement = checkForIndelAtLocus(read, position);
       
        if (readElement != null) {
          Integer ymInt = (Integer) read.getAttribute(ReadAdjuster.MISMATCHES_TO_CONTIG_TAG);
          if (ymInt != null) {
            int ym = ymInt;
            if (ym == 0) {
              mismatch0Count++;
            }
            if (ym <= 1) {
              mismatch1Count++;
            }
            totalMismatchCount += ym;
          }
        } else if (matchesReference(read, position)) {
          tumorRefCount += 1;
        }
       
        if (tumorIndel == null && readElement != null) {
          tumorIndel = readElement.getCigarElement();
          tumorCount = 1;
          maxContigMapq = Math.max(maxContigMapq, read.getIntegerAttribute(ReadAdjuster.CONTIG_QUALITY_TAG));
          if (readElement.getInsertBases() != null) {
            updateInsertBases(insertBasesMap, readElement.getInsertBases());
          }
          minReadIndex = readElement.getReadIndex() < minReadIndex ? readElement.getReadIndex() : minReadIndex;
          maxReadIndex = readElement.getReadIndex() > maxReadIndex ? readElement.getReadIndex() : maxReadIndex;
        } else if (tumorIndel != null && readElement != null) {
          if (tumorIndel.equals(readElement.getCigarElement())) {
            // Increment tumor indel support count
            tumorCount += 1;
            maxContigMapq = Math.max(maxContigMapq, read.getIntegerAttribute(ReadAdjuster.CONTIG_QUALITY_TAG));
            if (readElement.getInsertBases() != null) {
              updateInsertBases(insertBasesMap, readElement.getInsertBases());
            }
            minReadIndex = readElement.getReadIndex() < minReadIndex ? readElement.getReadIndex() : minReadIndex;
            maxReadIndex = readElement.getReadIndex() > maxReadIndex ? readElement.getReadIndex() : maxReadIndex;
 
          } else {
            // We will not deal with multiple indels at a single locus for now.
            tumorIndel = null;
            tumorCount = 0;
            break;
          }
        }
       
        if (!hasSufficientDistanceFromReadEnd && tumorIndel != null && readElement != null && readElement.getCigarElement().equals(tumorIndel)) {
          hasSufficientDistanceFromReadEnd = sufficientDistanceFromReadEnd(read, readElement.getReadIndex());
        }
      }
    }
   
    float tumorFraction = (float) tumorCount / (float) tumorReads.getReads().size();
   
    if (tumorCount >= MIN_SUPPORTING_READS && hasSufficientDistanceFromReadEnd && tumorFraction >= MIN_TUMOR_FRACTION) {
     
      for (SAMRecord read : normalReads.getReads()) {
        if (!read.getDuplicateReadFlag()) {
          IndelInfo normalInfo = checkForIndelAtLocus(read.getAlignmentStart(), read.getCigar(), position);
         
          if (normalInfo != null && sufficientDistanceFromReadEnd(read, normalInfo.getReadIndex())) {
            normalCount += 1;         
          } else if (normalInfo == null && matchesReference(read, position)) {
            normalRefCount += 1;
          }
        }
      }
    }
   
    if (tumorIndel != null && !isNormalCountOK(normalCount, normalReads.getReads().size(), tumorCount, tumorReads.getReads().size())) {
      tumorIndel = null;
      tumorCount = 0;
    }
   
    if (tumorCount >= MIN_SUPPORTING_READS && hasSufficientDistanceFromReadEnd && tumorFraction >= MIN_TUMOR_FRACTION) {
      String insertBases = null;
      if (tumorIndel.getOperator() == CigarOperator.I) {
        insertBases = getInsertBaseConsensus(insertBasesMap, tumorIndel.getLength());
      }
     
      int repeatPeriod = getRepeatPeriod(chromosome, position, tumorIndel, insertBases);
     
      double qual = calcPhredScaledQuality(normalRefCount, normalCount, tumorRefCount, tumorCount);
View Full Code Here

Examples of net.sf.samtools.CigarElement

    int readPos = 0;
    int refPosInRead = read.getAlignmentStart();
    int cigarElementIdx = 0;
   
    while (refPosInRead <= locus.posStop && cigarElementIdx < read.getCigar().numCigarElements() && readPos < read.getReadLength()) {
      CigarElement elem = read.getCigar().getCigarElement(cigarElementIdx++);
     
      switch(elem.getOperator()) {
        case H: //NOOP
          break;
        case I:
          if (isWithin(refPosInRead, locus.posStart, locus.posStop)) {
            return true;
          }
          // Fall through to next case
        case S:
          readPos += elem.getLength();
          break;
        case D:
          if (isWithin(refPosInRead, locus.posStart, locus.posStop)) {
            return true;
          }
          // Fall through to next case
        case N:
          refPosInRead += elem.getLength();
          break;
        case M:
          readPos += elem.getLength();
          refPosInRead += elem.getLength();
          break;
        default:
          throw new IllegalArgumentException("Invalid Cigar Operator: " + elem.getOperator() + " for read: " + read.getSAMString());         
      }
    }
   
    return false;
  }
View Full Code Here

Examples of net.sf.samtools.CigarElement

 
  protected Cigar shiftCigarLeft(Cigar cigar, int positionsToShift) {
    Cigar newCigar = new Cigar();
   
    for (int i=0; i<cigar.getCigarElements().size(); i++) {
      CigarElement elem = cigar.getCigarElement(i);
     
      if (isFirstNonSoftClippedElem(i, cigar)) {
        int newLen = elem.getLength() - positionsToShift;
       
        if (newLen > 0) {
          CigarElement newElem = new CigarElement(newLen, elem.getOperator());
          newCigar.add(newElem);
        }
      } else if (isLastNonSoftClippedElem(i, cigar)) {
        if (elem.getOperator() == CigarOperator.M) {
          CigarElement newElem = new CigarElement(elem.getLength() + positionsToShift, CigarOperator.M);
          newCigar.add(newElem);
        } else {
          CigarElement newElem = new CigarElement(positionsToShift, CigarOperator.M);
          newCigar.add(elem);
          newCigar.add(newElem);
        }
      } else {
        newCigar.add(elem);
View Full Code Here

Examples of net.sf.samtools.CigarElement

  @Test (groups = "unit" )
  public void testShiftCigarLeft_basic() {
    Cigar cigar = new Cigar();
   
    cigar.add(new CigarElement(10, CigarOperator.M));
    cigar.add(new CigarElement(3, CigarOperator.D));
    cigar.add(new CigarElement(40, CigarOperator.M));
   
    Cigar newCigar;

    newCigar = indelShifter.shiftCigarLeft(cigar, 10);
    Assert.assertEquals(newCigar.toString(), "3D50M");
View Full Code Here

Examples of net.sf.samtools.CigarElement

 
  @Test (groups = "unit" )
  public void testShiftCigarLeft_softClipping() {
    Cigar cigar = new Cigar();
   
    cigar.add(new CigarElement(2, CigarOperator.S));
    cigar.add(new CigarElement(6, CigarOperator.M));
    cigar.add(new CigarElement(2, CigarOperator.I));
    cigar.add(new CigarElement(30, CigarOperator.M));
    cigar.add(new CigarElement(10, CigarOperator.S));
   
    Cigar newCigar;

    newCigar = indelShifter.shiftCigarLeft(cigar, 6);
    Assert.assertEquals(newCigar.toString(), "2S2I36M10S");
View Full Code Here

Examples of net.sf.samtools.CigarElement

 
  @Test (groups = "unit" )
  public void testShiftCigarLeft_insertAtTail() {
    Cigar cigar = new Cigar();
   
    cigar.add(new CigarElement(40, CigarOperator.M));
    cigar.add(new CigarElement(10, CigarOperator.I));
   
    Cigar newCigar;

    newCigar = indelShifter.shiftCigarLeft(cigar, 40);
    Assert.assertEquals(newCigar.toString(), "10I40M");
View Full Code Here

Examples of net.sf.samtools.CigarElement

 
  @Test (groups = "unit" )
  public void testShiftCigarLeft_multipleIndels() {
    Cigar cigar = new Cigar();
   
    cigar.add(new CigarElement(20, CigarOperator.M));
    cigar.add(new CigarElement(1, CigarOperator.I));
    cigar.add(new CigarElement(5, CigarOperator.M));
    cigar.add(new CigarElement(3, CigarOperator.D));
    cigar.add(new CigarElement(24, CigarOperator.M));
   
    Cigar newCigar;
   
    newCigar = indelShifter.shiftCigarLeft(cigar, 20);
    Assert.assertEquals(newCigar.toString(), "1I5M3D44M");
View Full Code Here

Examples of net.sf.samtools.CigarElement

  @Test (groups = "unit" )
  public void testShiftCigarLeft_complex() {
    //3S69M1I18M1D9M
    Cigar cigar = new Cigar();
   
    cigar.add(new CigarElement(3, CigarOperator.S));
    cigar.add(new CigarElement(69, CigarOperator.M));
    cigar.add(new CigarElement(1, CigarOperator.I));
    cigar.add(new CigarElement(18, CigarOperator.M));
    cigar.add(new CigarElement(1, CigarOperator.D));
    cigar.add(new CigarElement(9, CigarOperator.M));
   
    Cigar newCigar;
   
    newCigar = indelShifter.shiftCigarLeft(cigar, 1);
    Assert.assertEquals(newCigar.toString(), "3S68M1I18M1D10M");
View Full Code Here

Examples of net.sf.samtools.CigarElement

      if (len <= newLength) {
        newCigarElements.add(ce);
        continue;
      }
      CigarElement newCe = new CigarElement(ce.getLength()
          - (record.getReadLength() - newLength), ce.getOperator());
      if (newCe.getLength() > 0)
        newCigarElements.add(newCe);
      break;
    }

    byte[] newBases = new byte[newLength];
View Full Code Here

Examples of net.sf.samtools.CigarElement

    int nm = 0;
    StringBuffer str = new StringBuffer();

    int size = cigarElements.size();
    for (i = y = 0, x = start; i < size; ++i) {
      CigarElement ce = cigarElements.get(i);
      int j, l = ce.getLength();
      CigarOperator op = ce.getOperator();
      if (op == CigarOperator.MATCH_OR_MISMATCH || op == CigarOperator.EQ
          || op == CigarOperator.X) {
        for (j = 0; j < l; ++j) {
          int z = y + j;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.