HTSJDK库Cigar类介绍

HTSJDK 库中的 Cigar 类用于表示比对过程中读取序列与参考序列之间的比对信息。CIGAR(Compact Idiosyncratic Gapped Alignment Report)字符串由多个操作符组成,这些操作符表示在比对过程中如何处理读取序列中的每个碱基。Cigar 类封装了这些信息,并提供了操作和访问这些信息的方法。

类简介

Cigar 类主要由一系列 CigarElement 对象组成,每个 CigarElement 包含一个操作符和一个长度。操作符包括匹配(M)、插入(I)、删除(D)、跳跃(N)、软剪切(S)、硬剪切(H)、匹配或不匹配(X)、匹配或不匹配(=)等。

Cigar.java源码

/*
 * The MIT License
 *
 * Copyright (c) 2009 The Broad Institute
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package htsjdk.samtools;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * A list of CigarElements, which describes how a read aligns with the reference.
 * E.g. the Cigar string 10M1D25M means
 * * match or mismatch for 10 bases
 * * deletion of 1 base
 * * match or mismatch for 25 bases
 *
 * c.f. https://samtools.github.io/hts-specs/SAMv1.pdf for complete CIGAR specification.
 */
public class Cigar implements Serializable, Iterable<CigarElement> {
    public static final long serialVersionUID = 1L;

    private final List<CigarElement> cigarElements = new ArrayList<CigarElement>();

    public Cigar() {
    }

    public Cigar(final List<CigarElement> cigarElements) {
        this.cigarElements.addAll(cigarElements);
    }

    public List<CigarElement> getCigarElements() {
        return Collections.unmodifiableList(cigarElements);
    }

    public CigarElement getCigarElement(final int i) {
        return cigarElements.get(i);
    }

    public void add(final CigarElement cigarElement) {
        cigarElements.add(cigarElement);
    }

    public int numCigarElements() {
        return cigarElements.size();
    }

    public boolean isEmpty() {
        return cigarElements.isEmpty();
    }

    /**
     * @return The number of reference bases that the read covers, excluding padding.
     */
    public int getReferenceLength() {
        int length = 0;
        for (final CigarElement element : cigarElements) {
            switch (element.getOperator()) {
                case M:
                case D:
                case N:
                case EQ:
                case X:
                    length += element.getLength();
                    break;
                default: break;
            }
        }
        return length;
    }

    /**
     * @return The number of reference bases that the read covers, including padding.
     */
    public int getPaddedReferenceLength() {
        int length = 0;
        for (final CigarElement element : cigarElements) {
            switch (element.getOperator()) {
                case M:
                case D:
                case N:
                case EQ:
                case X:
                case P:
                    length += element.getLength();
                    break;
                default: break;
            }
        }
        return length;
    }

    /**
     * @return The number of read bases that the read covers.
     */
    public int getReadLength() {
        return getReadLength(cigarElements);
    }

    /**
     * @return The number of read bases that the read covers.
     */
    public static int getReadLength(final List<CigarElement> cigarElements) {
        int length = 0;
        for (final CigarElement element : cigarElements) {
            if (element.getOperator().consumesReadBases()){
                    length += element.getLength();
            }
        }
        return length;
    }

    /**
     * Exhaustive validation of CIGAR.
     * Note that this method deliberately returns null rather than Collections.emptyList() if there
     * are no validation errors, because callers tend to assume that if a non-null list is returned, it is modifiable.
     * @param readName For error reporting only.  May be null if not known.
     * @param recordNumber For error reporting only.  May be -1 if not known.
     * @return List 

相关推荐

  1. HTSJDKCigar介绍

    2024-07-18 00:34:03       23 阅读
  2. CIFAR-10数据集和CIFAR-100数据集简单介绍

    2024-07-18 00:34:03       47 阅读
  3. ml_collections介绍

    2024-07-18 00:34:03       57 阅读
  4. cpptrace 介绍

    2024-07-18 00:34:03       54 阅读
  5. C++ filesystem介绍

    2024-07-18 00:34:03       42 阅读
  6. Numpy介绍

    2024-07-18 00:34:03       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 00:34:03       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 00:34:03       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 00:34:03       57 阅读
  4. Python语言-面向对象

    2024-07-18 00:34:03       68 阅读

热门阅读

  1. Html_Css问答集(9)

    2024-07-18 00:34:03       17 阅读
  2. 2024.7.17

    2024-07-18 00:34:03       26 阅读
  3. Web前端-Web开发CSS基础4-显示

    2024-07-18 00:34:03       18 阅读
  4. xml 标记语言介绍

    2024-07-18 00:34:03       22 阅读
  5. C# lock关键字

    2024-07-18 00:34:03       18 阅读
  6. C# —— 泛型

    2024-07-18 00:34:03       22 阅读
  7. 利用Postman进行自动化测试:从基础到进阶

    2024-07-18 00:34:03       20 阅读
  8. 河南萌新联赛2024第(一)场:河南农业大学

    2024-07-18 00:34:03       20 阅读
  9. ZC2205-24V500mAUltralow-Quiescent-Current LDO

    2024-07-18 00:34:03       16 阅读
  10. golang项目中gorm框架的配置和具体使用

    2024-07-18 00:34:03       20 阅读