当前位置: 首页 > news >正文

GATK AlleleList接口介绍

在 GATK(Genome Analysis Toolkit)中,AlleleList 接口是一个用来表示等位基因(alleles)列表的接口。Allele 是遗传学中用于表示某一特定基因座的不同形式的一个基本单位。AlleleList 接口定义了一些操作,使得处理和访问一组等位基因更加方便。

AlleleList 的实现类和继承接口

使用场景

AlleleList 及其实现类在 GATK 中主要用于表示和操作基因型数据中的等位基因集合。典型场景包括:

  • 变异检测:在不同样本中检测和分析不同的等位基因时,需要管理多个等位基因的集合,这时候会用到 AlleleList
  • 基因型计算:在计算样本的基因型时,可能需要迭代多个等位基因,并根据等位基因的组合进行计算。

通过 AlleleList 接口,GATK 提供了一个统一的方式来处理等位基因列表,增强了代码的可读性和模块化,使得等位基因的管理变得更加直观和高效。

AlleleList接口源码

package org.broadinstitute.hellbender.utils.genotyper;import htsjdk.variant.variantcontext.Allele;
import org.broadinstitute.hellbender.utils.Utils;import java.util.AbstractList;
import java.util.List;/*** Minimal interface for random access to a collection of Alleles.*/
//Note: Names in this interface are unusual because of name clash in a subclass.
// For example the name of AlleleList.alleleCount() cannot be simply size(), as would be usual,
// because {@link ReadLikelihoods} implements AlleleList and SampleList and then size() would be ambiguous.
public interface AlleleList<A extends Allele> {static <A extends Allele> AlleleList<A> newList(final List<A> alleles) {return new IndexedAlleleList<A>(alleles);}/*** Returns the number of alleles in this AlleleList.*/int numberOfAlleles();/*** Returns the index of the given Allele in this AlleleList.* Returns a negative number if the given allele is not present in this AlleleList.* @throws IllegalArgumentException if allele is null.*/int indexOfAllele(final Allele allele);/*** Returns the allele at the given index in this AlleleList.* @throws IllegalArgumentException if index is negative or equal* to or higher than the number of elements in this AlleleList {@link AlleleList#numberOfAlleles()}).*/A getAllele(final int index);/*** Returns <code>true</code> if this AlleleList contains the specified allele* and <code>false</code> otherwise.*/default boolean containsAllele(final Allele allele) {return indexOfAllele(allele) >= 0;}AlleleList<Allele> EMPTY_LIST = new AlleleList<Allele>() {@Overridepublic int numberOfAlleles() {return 0;}@Overridepublic int indexOfAllele(final Allele allele) {Utils.nonNull(allele);return -1;}@Overridepublic Allele getAllele(final int index) {throw new IllegalArgumentException("allele index is out of range");  //we know this without checking because it's an empty list}};/*** Returns an unmodifiable empty allele-list.* @param <A> the allele class.* @return never {@code null}.*/@SuppressWarnings("unchecked")static <A extends Allele> AlleleList<A> emptyAlleleList() {return (AlleleList<A>) EMPTY_LIST;}/*** Checks whether two allele lists are in fact the same.* @param first one list to compare.* @param second another list to compare.** @throws IllegalArgumentException if if either list is {@code null}.** @return {@code true} iff both list are equal.*/static <A extends Allele> boolean equals(final AlleleList<A> first, final AlleleList<A> second) {if (first == null || second == null) {throw new IllegalArgumentException("no null list allowed");}final int alleleCount = first.numberOfAlleles();if (alleleCount != second.numberOfAlleles()) {return false;}for (int i = 0; i < alleleCount; i++) {final A firstSample = first.getAllele(i);Utils.nonNull(firstSample, "no null samples allowed in sample-lists: first list at " + i);final A secondSample = second.getAllele(i);Utils.nonNull(secondSample,"no null samples allowed in sample-list: second list at " + i);if (!firstSample.equals(secondSample)) {return false;}}return true;}/*** Resolves the index of the reference allele in an allele-list.** <p>*     If there is no reference allele, it returns -1. If there is more than one reference allele,*     it returns the first occurrence (lowest index).* </p>*** @throws IllegalArgumentException if {@code list} is {@code null}.** @return -1 if there is no reference allele, or a values in [0,{@code list.alleleCount()}).*/default int indexOfReference() {final int alleleCount = this.numberOfAlleles();for (int i = 0; i < alleleCount; i++) {if (this.getAllele(i).isReference()) {return i;}}return -1;}/*** Returns a {@link List} unmodifiable view of this allele-list** @return never {@code null}.*/default List<A> asListOfAlleles() {return new AbstractList<A>() {@Overridepublic A get(final int index) {return AlleleList.this.getAllele(index);}@Overridepublic int size() {return AlleleList.this.numberOfAlleles();}};}/*** Returns a permutation between two allele lists.* @param target the target allele list.** @throws IllegalArgumentException if {@code target} is {@code null}, or* elements in {@code target} is not contained in {@code this}** @return never {@code null}*/default AlleleListPermutation<A> permutation(final AlleleList<A> target) {if (equals(this, target)) {return new NonPermutation<>(this);} else {return new ActualPermutation<>(this, target);}}/*** This is the identity permutation.*/final class NonPermutation<A extends Allele> implements AlleleListPermutation<A> {private final AlleleList<A> list;NonPermutation(final AlleleList<A> original) {list = original;}@Overridepublic boolean isPartial() {return false;}@Overridepublic boolean isNonPermuted() {return true;}@Overridepublic int toIndex(final int fromIndex) {return fromIndex;}@Overridepublic int fromIndex(final int toIndex) {return toIndex;}@Overridepublic boolean isKept(final int fromIndex) { return true; }@Overridepublic int fromSize() {return list.numberOfAlleles();}@Overridepublic int toSize() {return list.numberOfAlleles();}@Overridepublic List<A> fromList() {return list.asListOfAlleles();}@Overridepublic List<A> toList() {return list.asListOfAlleles();}@Overridepublic int numberOfAlleles() {return list.numberOfAlleles();}@Overridepublic int indexOfAllele(final Allele allele) {return list.indexOfAllele(allele);}@Overridepublic A getAllele(final int index) {return list.getAllele(index);}}final class ActualPermutation<A extends Allele> implements AlleleListPermutation<A> {private final AlleleList<A> from;private final AlleleList<A> to;private final int[] fromIndex;private final boolean[] keptFromIndices;private final boolean nonPermuted;private final boolean isPartial;private ActualPermutation(final AlleleList<A> original, final AlleleList<A> target) {this.from = original;this.to = target;keptFromIndices = new boolean[original.numberOfAlleles()];final int toSize = target.numberOfAlleles();final int fromSize = original.numberOfAlleles();if (fromSize < toSize) {throw new IllegalArgumentException("target allele list is not a permutation of the original allele list");}fromIndex = new int[toSize];boolean nonPermuted = fromSize == toSize;this.isPartial = !nonPermuted;for (int i = 0; i < toSize; i++) {final int originalIndex = original.indexOfAllele(target.getAllele(i));if (originalIndex < 0) {throw new IllegalArgumentException("target allele list is not a permutation of the original allele list");}keptFromIndices[originalIndex] = true;fromIndex[i] = originalIndex;nonPermuted &= originalIndex == i;}this.nonPermuted = nonPermuted;}@Overridepublic boolean isPartial() {return isPartial;}@Overridepublic boolean isNonPermuted() {return nonPermuted;}@Overridepublic int toIndex(final int fromIndex) {return to.indexOfAllele(from.getAllele(fromIndex));}@Overridepublic int fromIndex(final int toIndex) {return fromIndex[toIndex];}@Overridepublic boolean isKept(final int fromIndex) {return keptFromIndices[fromIndex];}@Overridepublic int fromSize() {return from.numberOfAlleles();}@Overridepublic int toSize() {return to.numberOfAlleles();}@Overridepublic List<A> fromList() {return from.asListOfAlleles();}@Overridepublic List<A> toList() {return to.asListOfAlleles();}@Overridepublic int numberOfAlleles() {return to.numberOfAlleles();}@Overridepublic int indexOfAllele(final Allele allele) {return to.indexOfAllele(allele);}@Overridepublic A getAllele(final int index) {return to.getAllele(index);}}
}


http://www.mrgr.cn/news/8395.html

相关文章:

  • 鸿蒙学习(四):泛型空安全模块导入导出
  • 分享从零开始学习网络设备配置--任务6.2 实现网络设备的远程管理
  • C语言 | Leetcode C语言题解之第355题设计推特
  • 后端完成api顺序
  • RK3588——网口实时传输视频
  • [Algorithm][综合训练][求最小公倍数][跳台阶][最长回文子串]详细讲解
  • 【机器学习】实验设计之一次一因子方法(OFAT)、全因子设计方法(FFD)响应面方法(RSM)和插值方法以及如何选择控制因子的概念
  • 【Java】/* 单向链表 - 底层实现 */
  • github访问加速项目@一键部署自动更改host修改加速Github访问
  • 12、stm32通过dht11读取温湿度
  • chromedriver下载地址大全(包括124.*后)以及替换exe后仍显示版本不匹配的问题
  • RK3588J正式发布Ubuntu桌面系统,丝滑又便捷!
  • CmoS相关概念
  • 【jetson交叉编译(6)】orin ubuntu的库安装,通过apt下载deb 库,然后的解压到具体位置/opt/test/3rd
  • 前端数据存在什么地方,刷新页面之后依旧存在
  • 零基础5分钟上手亚马逊云科技-搭建CDN加速应用访问
  • Spring Boot结合RabbitMQ使用总结
  • K8S 无状态应用有状态应用
  • 游戏开发设计模式之组件模式
  • Java 面向对象的三大特性和五大基本原则