jpayne@69: # cython: language_level=3 jpayne@69: ############################################################################### jpayne@69: ############################################################################### jpayne@69: ## Cython wrapper for htslib VCF/BCF reader/writer jpayne@69: ############################################################################### jpayne@69: # jpayne@69: # The MIT License jpayne@69: # jpayne@69: # Copyright (c) 2015, 2016 Kevin Jacobs (jacobs@bioinformed.com) jpayne@69: # jpayne@69: # Permission is hereby granted, free of charge, to any person obtaining a jpayne@69: # copy of this software and associated documentation files (the "Software"), jpayne@69: # to deal in the Software without restriction, including without limitation jpayne@69: # the rights to use, copy, modify, merge, publish, distribute, sublicense, jpayne@69: # and/or sell copies of the Software, and to permit persons to whom the jpayne@69: # Software is furnished to do so, subject to the following conditions: jpayne@69: # jpayne@69: # The above copyright notice and this permission notice shall be included in jpayne@69: # all copies or substantial portions of the Software. jpayne@69: # jpayne@69: # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR jpayne@69: # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, jpayne@69: # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL jpayne@69: # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER jpayne@69: # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING jpayne@69: # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER jpayne@69: # DEALINGS IN THE SOFTWARE. jpayne@69: # jpayne@69: ############################################################################### jpayne@69: jpayne@69: from libc.stdint cimport int8_t, int16_t, int32_t, int64_t jpayne@69: from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t jpayne@69: from libc.stdlib cimport malloc, calloc, realloc, free jpayne@69: from libc.string cimport memcpy, memcmp, memmove, strncpy, strlen, strdup jpayne@69: jpayne@69: from pysam.libchtslib cimport * jpayne@69: jpayne@69: jpayne@69: cdef class VariantHeader(object): jpayne@69: cdef bcf_hdr_t *ptr jpayne@69: jpayne@69: cdef _add_sample(self, name) jpayne@69: cdef _hdr_sync(self) jpayne@69: cdef _subset_samples(self, include_samples) jpayne@69: jpayne@69: jpayne@69: cdef class VariantHeaderRecord(object): jpayne@69: cdef readonly VariantHeader header jpayne@69: cdef bcf_hrec_t *ptr jpayne@69: jpayne@69: jpayne@69: cdef class VariantHeaderRecords(object): jpayne@69: cdef readonly VariantHeader header jpayne@69: jpayne@69: jpayne@69: cdef class VariantHeaderContigs(object): jpayne@69: cdef readonly VariantHeader header jpayne@69: jpayne@69: jpayne@69: cdef class VariantHeaderSamples(object): jpayne@69: cdef readonly VariantHeader header jpayne@69: jpayne@69: jpayne@69: cdef class VariantContig(object): jpayne@69: cdef readonly VariantHeader header jpayne@69: cdef int id jpayne@69: jpayne@69: jpayne@69: cdef class VariantMetadata(object): jpayne@69: cdef readonly VariantHeader header jpayne@69: cdef int type jpayne@69: cdef int id jpayne@69: jpayne@69: jpayne@69: cdef class VariantHeaderMetadata(object): jpayne@69: cdef readonly VariantHeader header jpayne@69: cdef int32_t type jpayne@69: jpayne@69: jpayne@69: cdef class VariantRecord(object): jpayne@69: cdef readonly VariantHeader header jpayne@69: cdef bcf1_t *ptr jpayne@69: jpayne@69: jpayne@69: cdef class VariantRecordFilter(object): jpayne@69: cdef VariantRecord record jpayne@69: jpayne@69: jpayne@69: cdef class VariantRecordFormat(object): jpayne@69: cdef VariantRecord record jpayne@69: jpayne@69: jpayne@69: cdef class VariantRecordInfo(object): jpayne@69: cdef VariantRecord record jpayne@69: jpayne@69: jpayne@69: cdef class VariantRecordSamples(object): jpayne@69: cdef VariantRecord record jpayne@69: jpayne@69: jpayne@69: cdef class VariantRecordSample(object): jpayne@69: cdef VariantRecord record jpayne@69: cdef readonly int32_t index jpayne@69: jpayne@69: jpayne@69: cdef class BaseIndex(object): jpayne@69: cdef tuple refs jpayne@69: cdef dict refmap jpayne@69: jpayne@69: jpayne@69: cdef class BCFIndex(BaseIndex): jpayne@69: cdef readonly VariantHeader header jpayne@69: cdef hts_idx_t *ptr jpayne@69: jpayne@69: jpayne@69: cdef class TabixIndex(BaseIndex): jpayne@69: cdef tbx_t *ptr jpayne@69: jpayne@69: jpayne@69: cdef class BaseIterator(object): jpayne@69: cdef VariantFile bcf jpayne@69: cdef hts_itr_t *iter jpayne@69: jpayne@69: jpayne@69: cdef class BCFIterator(BaseIterator): jpayne@69: cdef BCFIndex index jpayne@69: jpayne@69: jpayne@69: cdef class TabixIterator(BaseIterator): jpayne@69: cdef TabixIndex index jpayne@69: cdef kstring_t line_buffer jpayne@69: jpayne@69: jpayne@69: cdef class VariantFile(HTSFile): jpayne@69: cdef readonly VariantHeader header jpayne@69: cdef readonly BaseIndex index jpayne@69: jpayne@69: cdef readonly bint drop_samples # true if sample information is to be ignored jpayne@69: jpayne@69: # FIXME: Temporary, use htsFormat when it is available jpayne@69: cdef readonly bint is_reading # true if file has begun reading records jpayne@69: cdef readonly bint header_written # true if header has already been written jpayne@69: jpayne@69: cpdef int write(self, VariantRecord record) except -1