在 HTSJDK 库中,FeatureCodec
接口和 Feature
接口分别扮演不同的角色,用于处理基因组数据的不同方面。下面是这两个接口的区别和各自的功能:
FeatureCodec
接口
主要功能
- 编码和解码:
FeatureCodec
接口的主要职责是定义如何将数据从文件格式解码为 Java 对象(即Feature
对象),以及如何将Feature
对象编码回文件格式。它提供了与数据存储和读取相关的操作。 - 支持多种格式:
FeatureCodec
可以支持多种格式的数据文件,如 VCF、BED、GTF 等。实现类通常需要定义如何处理特定格式的数据。 - 格式识别:通过
canDecode
方法,FeatureCodec
可以检查它是否支持解码特定格式的文件。
实现类/接口
源码:
/*
* Copyright (c) 2007-2010 by The Broad Institute, Inc. and the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* This software is licensed under the terms of the GNU Lesser General Public License (LGPL), Version 2.1 which
* is available at http://www.opensource.org/licenses/lgpl-2.1.php.
*
* THE SOFTWARE IS PROVIDED "AS IS." THE BROAD AND MIT MAKE NO REPRESENTATIONS OR WARRANTIES OF
* ANY KIND CONCERNING THE SOFTWARE, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT
* OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. IN NO EVENT SHALL THE BROAD OR MIT, OR THEIR
* RESPECTIVE TRUSTEES, DIRECTORS, OFFICERS, EMPLOYEES, AND AFFILIATES BE LIABLE FOR ANY DAMAGES OF
* ANY KIND, INCLUDING, WITHOUT LIMITATION, INCIDENTAL OR CONSEQUENTIAL DAMAGES, ECONOMIC
* DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER THE BROAD OR MIT SHALL
* BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE
* FOREGOING.
*/
package htsjdk.tribble;
import htsjdk.io.IOPath;
import htsjdk.samtools.util.LocationAware;
import htsjdk.tribble.index.tabix.TabixFormat;
import java.io.IOException;
import java.io.InputStream;
/**
* The base interface for classes that read in features.
* <p/>
* FeatureCodecs must implement several key methods:
* <p/>
* <ul>
* <li>{@link #makeSourceFromStream} Return a {@link SOURCE} for this {@link FeatureCodec} given an input stream that is buffered.
* <li>{@link #makeIndexableSourceFromStream} Return a {@link SOURCE} for this {@link FeatureCodec} that implements {@link LocationAware},
* and is thus suitable for use during indexing. During the indexing process, the indexer passes the {@link SOURCE} to the codec
* to consume Features from the underlying