当前位置: 首页>>代码示例>>Java>>正文


Java Cigar类代码示例

本文整理汇总了Java中htsjdk.samtools.Cigar的典型用法代码示例。如果您正苦于以下问题:Java Cigar类的具体用法?Java Cigar怎么用?Java Cigar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Cigar类属于htsjdk.samtools包,在下文中一共展示了Cigar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: trim

import htsjdk.samtools.Cigar; //导入依赖的package包/类
/**
 * Create a new Haplotype derived from this one that exactly spans the provided location
 * <p>
 * Note that this haplotype must have a contain a genome loc for this operation to be successful.  If no
 * GenomeLoc is contained than @throws an IllegalStateException
 * <p>
 * Also loc must be fully contained within this Haplotype's genomeLoc.  If not an IllegalArgumentException is
 * thrown.
 *
 * @param loc a location completely contained within this Haplotype's location
 * @return a new Haplotype within only the bases spanning the provided location, or null for some reason the haplotype would be malformed if
 */
public Haplotype trim(final GenomeLoc loc) {
    if (loc == null) throw new IllegalArgumentException("Loc cannot be null");
    if (genomeLocation == null)
        throw new IllegalStateException("Cannot trim a Haplotype without containing GenomeLoc");
    if (!genomeLocation.containsP(loc))
        throw new IllegalArgumentException("Can only trim a Haplotype to a containing span.  My loc is " + genomeLocation + " but wanted trim to " + loc);
    if (getCigar() == null)
        throw new IllegalArgumentException("Cannot trim haplotype without a cigar " + this);

    final int newStart = loc.getStart() - this.genomeLocation.getStart();
    final int newStop = newStart + loc.size() - 1;
    final byte[] newBases = AlignmentUtils.getBasesCoveringRefInterval(newStart, newStop, getBases(), 0, getCigar());
    final Cigar newCigar = AlignmentUtils.trimCigarByReference(getCigar(), newStart, newStop);

    if (newBases == null || AlignmentUtils.startsOrEndsWithInsertionOrDeletion(newCigar))
        // we cannot meaningfully chop down the haplotype, so return null
        return null;

    final Haplotype ret = new Haplotype(newBases, isReference());
    ret.setCigar(newCigar);
    ret.setGenomeLocation(loc);
    ret.setAlignmentStartHapwrtRef(newStart + getAlignmentStartHapwrtRef());
    return ret;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:37,代码来源:Haplotype.java

示例2: combineAdjacentCigarElements

import htsjdk.samtools.Cigar; //导入依赖的package包/类
/**
 * Combines equal adjacent elements of a Cigar object
 *
 * @param rawCigar the cigar object
 * @return a combined cigar object
 */
public static Cigar combineAdjacentCigarElements(Cigar rawCigar) {
    Cigar combinedCigar = new Cigar();
    CigarElement lastElement = null;
    int lastElementLength = 0;
    for (CigarElement cigarElement : rawCigar.getCigarElements()) {
        if (lastElement != null &&
                ((lastElement.getOperator() == cigarElement.getOperator()) ||
                        (lastElement.getOperator() == CigarOperator.I && cigarElement.getOperator() == CigarOperator.D) ||
                        (lastElement.getOperator() == CigarOperator.D && cigarElement.getOperator() == CigarOperator.I)))
            lastElementLength += cigarElement.getLength();
        else
        {
            if (lastElement != null)
                combinedCigar.add(new CigarElement(lastElementLength, lastElement.getOperator()));

            lastElement = cigarElement;
            lastElementLength = cigarElement.getLength();
        }
    }
    if (lastElement != null)
        combinedCigar.add(new CigarElement(lastElementLength, lastElement.getOperator()));

    return combinedCigar;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:31,代码来源:CigarUtils.java

示例3: moveCigarLeft

import htsjdk.samtools.Cigar; //导入依赖的package包/类
/**
 * Move the indel in a given cigar string one base to the left
 *
 * @param cigar          original cigar
 * @param indexOfIndel   the index of the indel cigar element
 * @return non-null cigar with indel moved one base to the left
 */
private static Cigar moveCigarLeft(Cigar cigar, int indexOfIndel) {
    // get the first few elements
    ArrayList<CigarElement> elements = new ArrayList<CigarElement>(cigar.numCigarElements());
    for (int i = 0; i < indexOfIndel - 1; i++)
        elements.add(cigar.getCigarElement(i));

    // get the indel element and move it left one base
    CigarElement ce = cigar.getCigarElement(indexOfIndel - 1);
    elements.add(new CigarElement(Math.max(ce.getLength() - 1, 0), ce.getOperator()));
    elements.add(cigar.getCigarElement(indexOfIndel));
    if (indexOfIndel + 1 < cigar.numCigarElements()) {
        ce = cigar.getCigarElement(indexOfIndel + 1);
        elements.add(new CigarElement(ce.getLength() + 1, ce.getOperator()));
    } else {
        elements.add(new CigarElement(1, CigarOperator.M));
    }

    // get the last few elements
    for (int i = indexOfIndel + 2; i < cigar.numCigarElements(); i++)
        elements.add(cigar.getCigarElement(i));
    return new Cigar(elements);
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:30,代码来源:AlignmentUtils.java

示例4: calcHardSoftOffset

import htsjdk.samtools.Cigar; //导入依赖的package包/类
/**
 * Compute the offset of the first "real" position in the cigar on the genome
 *
 * This is defined as a first position after a run of Hs followed by a run of Ss
 *
 * @param cigar A non-null cigar
 * @return the offset (from 0) of the first on-genome base
 */
private int calcHardSoftOffset(final Cigar cigar) {
    final List<CigarElement> elements = cigar.getCigarElements();

    int size = 0;
    int i = 0;
    while ( i < elements.size() && elements.get(i).getOperator() == CigarOperator.HARD_CLIP ) {
        size += elements.get(i).getLength();
        i++;
    }
    while ( i < elements.size() && elements.get(i).getOperator() == CigarOperator.SOFT_CLIP ) {
        size += elements.get(i).getLength();
        i++;
    }

    return size;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:25,代码来源:ClippingOp.java

示例5: getReadCoordinateForReferenceCoordinate

import htsjdk.samtools.Cigar; //导入依赖的package包/类
public static int getReadCoordinateForReferenceCoordinate(final int alignmentStart, final Cigar cigar, final int refCoord, final ClippingTail tail, final boolean allowGoalNotReached) {
    Pair<Integer, Boolean> result = getReadCoordinateForReferenceCoordinate(alignmentStart, cigar, refCoord, allowGoalNotReached);
    int readCoord = result.getFirst();

    // Corner case one: clipping the right tail and falls on deletion, move to the next
    // read coordinate. It is not a problem for the left tail because the default answer
    // from getReadCoordinateForReferenceCoordinate is to give the previous read coordinate.
    if (result.getSecond() && tail == ClippingTail.RIGHT_TAIL)
        readCoord++;

    // clipping the left tail and first base is insertion, go to the next read coordinate
    // with the same reference coordinate. Advance to the next cigar element, or to the
    // end of the read if there is no next element.
    final CigarElement firstElementIsInsertion = readStartsWithInsertion(cigar);
    if (readCoord == 0 && tail == ClippingTail.LEFT_TAIL && firstElementIsInsertion != null)
        readCoord = Math.min(firstElementIsInsertion.getLength(), cigar.getReadLength() - 1);

    return readCoord;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:20,代码来源:ReadUtils.java

示例6: makeCigarForStrictPrefixAndSuffix

import htsjdk.samtools.Cigar; //导入依赖的package包/类
/**
 * Creates a CIGAR for the case where the prefix/suffix match combination encompasses an entire sequence
 *
 * @param reference            the reference sequence
 * @param alternate            the alternate sequence
 * @param matchingPrefix       the prefix match size
 * @param matchingSuffix       the suffix match size
 * @return non-null CIGAR
 */
private Cigar makeCigarForStrictPrefixAndSuffix(final byte[] reference, final byte[] alternate, final int matchingPrefix, final int matchingSuffix) {

    final List<CigarElement> result = new ArrayList<CigarElement>();

    // edge case: no D or I element
    if ( reference.length == alternate.length ) {
        result.add(makeElement(State.MATCH, matchingPrefix + matchingSuffix));
    } else {
        // add the first M element
        if ( matchingPrefix > 0 )
            result.add(makeElement(State.MATCH, matchingPrefix));

        // add the D or I element
        if ( alternate.length > reference.length )
            result.add(makeElement(State.INSERTION, alternate.length - reference.length));
        else // if ( reference.length > alternate.length )
            result.add(makeElement(State.DELETION, reference.length - alternate.length));

        // add the last M element
        if ( matchingSuffix > 0 )
            result.add(makeElement(State.MATCH, matchingSuffix));
    }

    return new Cigar(result);
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:35,代码来源:GlobalEdgeGreedySWPairwiseAlignment.java

示例7: reclipCigar

import htsjdk.samtools.Cigar; //导入依赖的package包/类
protected static Cigar reclipCigar(Cigar cigar, SAMRecord read) {
    ArrayList<CigarElement> elements = new ArrayList<CigarElement>();

    int i = 0;
    int n = read.getCigar().numCigarElements();
    while (i < n && isClipOperator(read.getCigar().getCigarElement(i).getOperator()))
        elements.add(read.getCigar().getCigarElement(i++));

    elements.addAll(cigar.getCigarElements());

    i++;
    while (i < n && !isClipOperator(read.getCigar().getCigarElement(i).getOperator()))
        i++;

    while (i < n && isClipOperator(read.getCigar().getCigarElement(i).getOperator()))
        elements.add(read.getCigar().getCigarElement(i++));

    return new Cigar(elements);
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:20,代码来源:IndelRealigner.java

示例8: setCigar

import htsjdk.samtools.Cigar; //导入依赖的package包/类
public void setCigar(Cigar cigar, boolean fixClippedCigar) {
    if (cigar == null) {
        newCigar = null;
        return;
    }

    if (fixClippedCigar && getReadBases().length < read.getReadLength())
        cigar = reclipCigar(cigar);

    // no change?
    if (read.getCigar().equals(cigar)) {
        newCigar = null;
        return;
    }

    // no indel?
    String str = cigar.toString();
    if (!str.contains("D") && !str.contains("I")) {

    }

    newCigar = cigar;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:24,代码来源:IndelRealigner.java

示例9: getNumClippedBasesAtStart

import htsjdk.samtools.Cigar; //导入依赖的package包/类
private int getNumClippedBasesAtStart(final SAMRecord read) {
    // compute total number of clipped bases (soft or hard clipped)
    // check for hard clips (never consider these bases):
    final Cigar c = read.getCigar();
    final CigarElement first = c.getCigarElement(0);

    int numStartClippedBases = 0;
    if (first.getOperator() == CigarOperator.H) {
        numStartClippedBases = first.getLength();
    }
    final byte[] unclippedReadBases = read.getReadBases();
    final byte[] unclippedReadQuals = read.getBaseQualities();

    // Do a stricter base clipping than provided by CIGAR string, since this one may be too conservative,
    // and may leave a string of Q2 bases still hanging off the reads.
    for (int i = numStartClippedBases; i < unclippedReadBases.length; i++) {
        if (unclippedReadQuals[i] < PairHMMIndelErrorModel.BASE_QUAL_THRESHOLD)
            numStartClippedBases++;
        else
            break;

    }

    return numStartClippedBases;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:26,代码来源:ReadPosRankSumTest.java

示例10: getNumClippedBasesAtEnd

import htsjdk.samtools.Cigar; //导入依赖的package包/类
private int getNumClippedBasesAtEnd(final GATKSAMRecord read) {
    // compute total number of clipped bases (soft or hard clipped)
    // check for hard clips (never consider these bases):
    final Cigar c = read.getCigar();
    CigarElement last = c.getCigarElement(c.numCigarElements() - 1);

    int numEndClippedBases = 0;
    if (last.getOperator() == CigarOperator.H) {
        numEndClippedBases = last.getLength();
    }
    final byte[] unclippedReadBases = read.getReadBases();
    final byte[] unclippedReadQuals = read.getBaseQualities();

    // Do a stricter base clipping than provided by CIGAR string, since this one may be too conservative,
    // and may leave a string of Q2 bases still hanging off the reads.
    for (int i = unclippedReadBases.length - numEndClippedBases - 1; i >= 0; i--) {
        if (unclippedReadQuals[i] < PairHMMIndelErrorModel.BASE_QUAL_THRESHOLD)
            numEndClippedBases++;
        else
            break;
    }

    return numEndClippedBases;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:25,代码来源:ReadPosRankSumTest.java

示例11: cigarIsOkayToMerge

import htsjdk.samtools.Cigar; //导入依赖的package包/类
/**
 * Determine whether the provided cigar is okay to merge into the reference path
 *
 * @param cigar    the cigar to analyze
 * @param requireFirstElementM if true, require that the first cigar element be an M operator in order for it to be okay
 * @param requireLastElementM  if true, require that the last cigar element be an M operator in order for it to be okay
 * @return true if it's okay to merge, false otherwise
 */
protected boolean cigarIsOkayToMerge(final Cigar cigar, final boolean requireFirstElementM, final boolean requireLastElementM) {

    final List<CigarElement> elements = cigar.getCigarElements();
    final int numElements = elements.size();

    // don't allow more than a couple of different ops
    if ( numElements == 0 || numElements > MAX_CIGAR_COMPLEXITY )
        return false;

    // the first element must be an M
    if ( requireFirstElementM && elements.get(0).getOperator() != CigarOperator.M )
        return false;

    // the last element must be an M
    if ( requireLastElementM && elements.get(numElements - 1).getOperator() != CigarOperator.M )
        return false;

    // note that there are checks for too many mismatches in the dangling branch later in the process

    return true;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:30,代码来源:DanglingChainMergingGraph.java

示例12: testShiftCigarLeft_multipleIndels

import htsjdk.samtools.Cigar; //导入依赖的package包/类
@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");
    
    newCigar = indelShifter.shiftCigarLeft(cigar, 10);
    Assert.assertEquals(newCigar.toString(), "10M1I5M3D34M");

    newCigar = indelShifter.shiftCigarLeft(cigar, 1);
    Assert.assertEquals(newCigar.toString(), "19M1I5M3D25M");
}
 
开发者ID:mozack,项目名称:abra2,代码行数:22,代码来源:IndelShifterTest.java

示例13: trimCigarByBases

import htsjdk.samtools.Cigar; //导入依赖的package包/类
public static Cigar trimCigarByBases(final Cigar cigar, final int start, final int end) {
    if (start < 0)
        throw new IllegalArgumentException("Start must be >= 0 but got " + start);
    if (end < start)
        throw new IllegalArgumentException("End " + end + " is < start = " + start);
    if (end > cigar.getReadLength())
        throw new IllegalArgumentException("End is beyond the cigar's read length " + end + " for cigar " + cigar);

    final Cigar result = trimCigar(cigar, start, end, false);

    final int expectedSize = end - start + 1;
    if (result.getReadLength() != expectedSize)
        throw new IllegalStateException("trimCigarByBases failure: start " + start + " end " + end + " for " + cigar
                + " resulted in cigar with wrong size " + result + " with size " + result.getReadLength()
                + " expected " + expectedSize + " for input cigar " + cigar);
    return result;
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:18,代码来源:AlignmentExtendUtils.java

示例14: leftAlignIndel

import htsjdk.samtools.Cigar; //导入依赖的package包/类
@Ensures("result != null")
public static Cigar leftAlignIndel(Cigar cigar, final byte[] refSeq, final byte[] readSeq, final int refIndex, final int readIndex, final boolean doNotThrowExceptionForMultipleIndels) {
    ensureLeftAlignmentHasGoodArguments(cigar, refSeq, readSeq, refIndex, readIndex);

    final int numIndels = countIndelElements(cigar);
    if ( numIndels == 0 )
        return cigar;
    if ( numIndels == 1 )
        return leftAlignSingleIndel(cigar, refSeq, readSeq, refIndex, readIndex, true);

    // if we got here then there is more than 1 indel in the alignment
    if ( doNotThrowExceptionForMultipleIndels )
        return cigar;

    throw new UnsupportedOperationException("attempting to left align a CIGAR that has more than 1 indel in its alignment but this functionality has not been implemented yet");
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:17,代码来源:AlignmentExtendUtils.java

示例15: moveCigarLeft

import htsjdk.samtools.Cigar; //导入依赖的package包/类
@Requires("cigar != null && indexOfIndel >= 0 && indexOfIndel < cigar.numCigarElements()")
@Ensures("result != null")
private static Cigar moveCigarLeft(Cigar cigar, int indexOfIndel) {
    // get the first few elements
    ArrayList<CigarElement> elements = new ArrayList<CigarElement>(cigar.numCigarElements());
    for (int i = 0; i < indexOfIndel - 1; i++)
        elements.add(cigar.getCigarElement(i));

    // get the indel element and move it left one base
    CigarElement ce = cigar.getCigarElement(indexOfIndel - 1);
    elements.add(new CigarElement(Math.max(ce.getLength() - 1, 0), ce.getOperator()));
    elements.add(cigar.getCigarElement(indexOfIndel));
    if (indexOfIndel + 1 < cigar.numCigarElements()) {
        ce = cigar.getCigarElement(indexOfIndel + 1);
        elements.add(new CigarElement(ce.getLength() + 1, ce.getOperator()));
    } else {
        elements.add(new CigarElement(1, CigarOperator.M));
    }

    // get the last few elements
    for (int i = indexOfIndel + 2; i < cigar.numCigarElements(); i++)
        elements.add(cigar.getCigarElement(i));
    return new Cigar(elements);
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:25,代码来源:AlignmentExtendUtils.java


注:本文中的htsjdk.samtools.Cigar类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。