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