You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

145 lines
4.0 KiB

  1. # cython: language_level=3
  2. ###############################################################################
  3. ###############################################################################
  4. ## Cython wrapper for htslib VCF/BCF reader/writer
  5. ###############################################################################
  6. #
  7. # The MIT License
  8. #
  9. # Copyright (c) 2015, 2016 Kevin Jacobs (jacobs@bioinformed.com)
  10. #
  11. # Permission is hereby granted, free of charge, to any person obtaining a
  12. # copy of this software and associated documentation files (the "Software"),
  13. # to deal in the Software without restriction, including without limitation
  14. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. # and/or sell copies of the Software, and to permit persons to whom the
  16. # Software is furnished to do so, subject to the following conditions:
  17. #
  18. # The above copyright notice and this permission notice shall be included in
  19. # all copies or substantial portions of the Software.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  24. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  26. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  27. # DEALINGS IN THE SOFTWARE.
  28. #
  29. ###############################################################################
  30. from libc.stdint cimport int8_t, int16_t, int32_t, int64_t
  31. from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t
  32. from libc.stdlib cimport malloc, calloc, realloc, free
  33. from libc.string cimport memcpy, memcmp, memmove, strncpy, strlen, strdup
  34. from pysam.libchtslib cimport *
  35. cdef class VariantHeader(object):
  36. cdef bcf_hdr_t *ptr
  37. cdef _add_sample(self, name)
  38. cdef _hdr_sync(self)
  39. cdef _subset_samples(self, include_samples)
  40. cdef class VariantHeaderRecord(object):
  41. cdef readonly VariantHeader header
  42. cdef bcf_hrec_t *ptr
  43. cdef class VariantHeaderRecords(object):
  44. cdef readonly VariantHeader header
  45. cdef class VariantHeaderContigs(object):
  46. cdef readonly VariantHeader header
  47. cdef class VariantHeaderSamples(object):
  48. cdef readonly VariantHeader header
  49. cdef class VariantContig(object):
  50. cdef readonly VariantHeader header
  51. cdef int id
  52. cdef class VariantMetadata(object):
  53. cdef readonly VariantHeader header
  54. cdef int type
  55. cdef int id
  56. cdef class VariantHeaderMetadata(object):
  57. cdef readonly VariantHeader header
  58. cdef int32_t type
  59. cdef class VariantRecord(object):
  60. cdef readonly VariantHeader header
  61. cdef bcf1_t *ptr
  62. cdef class VariantRecordFilter(object):
  63. cdef VariantRecord record
  64. cdef class VariantRecordFormat(object):
  65. cdef VariantRecord record
  66. cdef class VariantRecordInfo(object):
  67. cdef VariantRecord record
  68. cdef class VariantRecordSamples(object):
  69. cdef VariantRecord record
  70. cdef class VariantRecordSample(object):
  71. cdef VariantRecord record
  72. cdef readonly int32_t index
  73. cdef class BaseIndex(object):
  74. cdef tuple refs
  75. cdef dict refmap
  76. cdef class BCFIndex(BaseIndex):
  77. cdef readonly VariantHeader header
  78. cdef hts_idx_t *ptr
  79. cdef class TabixIndex(BaseIndex):
  80. cdef tbx_t *ptr
  81. cdef class BaseIterator(object):
  82. cdef VariantFile bcf
  83. cdef hts_itr_t *iter
  84. cdef class BCFIterator(BaseIterator):
  85. cdef BCFIndex index
  86. cdef class TabixIterator(BaseIterator):
  87. cdef TabixIndex index
  88. cdef kstring_t line_buffer
  89. cdef class VariantFile(HTSFile):
  90. cdef readonly VariantHeader header
  91. cdef readonly BaseIndex index
  92. cdef readonly bint drop_samples # true if sample information is to be ignored
  93. # FIXME: Temporary, use htsFormat when it is available
  94. cdef readonly bint is_reading # true if file has begun reading records
  95. cdef readonly bint header_written # true if header has already been written
  96. cpdef int write(self, VariantRecord record) except -1